Skip to content

Commit a37955f

Browse files
AchilleSteve van Loben Sels
Achille
and
Steve van Loben Sels
authored
0.4 fix tls address panic (#478)
* 0.4: fix panic when TLS is enabled * 0.4: fix panic when establishing TLS connections * cleanup * Update transport_test.go Co-authored-by: Steve van Loben Sels <[email protected]> * validate that an error is returned Co-authored-by: Steve van Loben Sels <[email protected]>
1 parent ad5061d commit a37955f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

transport.go

+4
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,10 @@ func (g *connGroup) connect(ctx context.Context) (*conn, error) {
997997
for i := range address {
998998
netConn, err = g.pool.dial(ctx, network[i], address[i])
999999
if err == nil {
1000+
netAddr = &networkAddress{
1001+
network: network[i],
1002+
address: address[i],
1003+
}
10001004
break
10011005
}
10021006
}

transport_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package kafka
2+
3+
import (
4+
"context"
5+
"crypto/tls"
6+
"net"
7+
"testing"
8+
)
9+
10+
func TestIssue477(t *testing.T) {
11+
// This test verifies that a connection attempt with a minimal TLS
12+
// configuration does not panic.
13+
l, err := net.Listen("tcp", "127.0.0.1:0")
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
defer l.Close()
18+
19+
cg := connGroup{
20+
addr: l.Addr(),
21+
pool: &connPool{
22+
dial: defaultDialer.DialContext,
23+
tls: &tls.Config{},
24+
},
25+
}
26+
27+
if _, err := cg.connect(context.Background()); err != nil {
28+
// An error is expected here because we are not actually establishing
29+
// a TLS connection to a kafka broker.
30+
t.Log(err)
31+
} else {
32+
t.Error("no error was reported when attempting to establish a TLS connection to a non-TLS endpoint")
33+
}
34+
}

0 commit comments

Comments
 (0)