Skip to content

Commit c37a0a2

Browse files
committed
Check the conn in nil before closing if failed connect()
It's possible that the reason connect failed is that the connection dropped/was reset and the conn is already nil, calling Close() on a nil conn causes a panic, so we're now checking that the conn is actually not nil before trying to close it and run the rest of the failed to connect code. resolves eclipse-paho#94
1 parent 51f0e19 commit c37a0a2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

client.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ func (c *client) Connect() Token {
190190

191191
rc = c.connect()
192192
if rc != packets.Accepted {
193-
c.conn.Close()
194-
c.conn = nil
193+
if c.conn != nil {
194+
c.conn.Close()
195+
c.conn = nil
196+
}
195197
//if the protocol version was explicitly set don't do any fallback
196198
if c.options.protocolVersionExplicit {
197199
ERROR.Println(CLI, "Connecting to", broker, "CONNACK was not CONN_ACCEPTED, but rather", packets.ConnackReturnCodes[rc])

0 commit comments

Comments
 (0)