Skip to content

Commit

Permalink
Fix panic in tests
Browse files Browse the repository at this point in the history
Reported in https://github.com/rabbitmq/amqp091-go/actions/runs/5333022714/jobs/9662961511

```
panic: runtime error: invalid memory address or nil pointer dereference
	panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x7e012c]

goroutine 3810 [running]:
github.com/rabbitmq/amqp091-go.(*Connection).IsClosed(...)
	D:/a/amqp091-go/amqp091-go/connection.go:455
github.com/rabbitmq/amqp091-go.(*Connection).Close(0x0)
	D:/a/amqp091-go/amqp091-go/connection.go:388 +0x4c
panic({0x86a960, 0xb32080})
	C:/hostedtoolcache/windows/go/1.20.5/x64/src/runtime/panic.go:890 +0x263
github.com/rabbitmq/amqp091-go.(*Connection).ConnectionState(...)
	D:/a/amqp091-go/amqp091-go/connection.go:317
github.com/rabbitmq/amqp091-go.TestTLSHandshake.func2()
	D:/a/amqp091-go/amqp091-go/tls_test.go:111 +0x27b
created by github.com/rabbitmq/amqp091-go.TestTLSHandshake
	D:/a/amqp091-go/amqp091-go/tls_test.go:104 +0x3e6
exit status 2
```

If DialTLS returns an error, c will be nil, causing a panic later on in
c.ConnectionState()

Signed-off-by: Aitor Pérez Cedres <[email protected]>
  • Loading branch information
Zerpet committed Jun 21, 2023
1 parent 4f02d9d commit f23ccf7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *tlsServer) Serve(t *testing.T) {
}

func startTLSServer(t *testing.T, cfg *tls.Config) tlsServer {
l, err := tls.Listen("tcp", "127.0.0.1:0", cfg)
l, err := tls.Listen("tcp", "127.0.0.1:3456", cfg)
if err != nil {
t.Fatalf("TLS server Listen error: %+v", err)
}
Expand Down Expand Up @@ -105,6 +105,7 @@ func TestTLSHandshake(t *testing.T) {
c, err := DialTLS(srv.URL, tlsClientConfig(t))
if err != nil {
errs <- fmt.Errorf("expected to open a TLS connection, got err: %v", err)
return
}
defer c.Close()

Expand Down

0 comments on commit f23ccf7

Please sign in to comment.