Skip to content

Commit

Permalink
Merge pull request #577 from ChIoT-Tech/master
Browse files Browse the repository at this point in the history
nil c.options.Dialer caused a panic. Would only have impacted users who manually created ClientOptions structure.
  • Loading branch information
MattBrittan committed Dec 28, 2021
2 parents 44f71c7 + 721bf9f commit 2d3b04d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client.go
Expand Up @@ -392,11 +392,16 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
DEBUG.Println(CLI, "using custom onConnectAttempt handler...")
tlsCfg = c.options.OnConnectAttempt(broker, c.options.TLSConfig)
}
dialer := c.options.Dialer
if dialer == nil { //
WARN.Println(CLI, "dialer was nil, using default")
dialer = &net.Dialer{Timeout: 30 * time.Second}
}
// Start by opening the network connection (tcp, tls, ws) etc
if c.options.CustomOpenConnectionFn != nil {
conn, err = c.options.CustomOpenConnectionFn(broker, c.options)
} else {
conn, err = openConnection(broker, tlsCfg, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions, c.options.Dialer)
conn, err = openConnection(broker, tlsCfg, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions, dialer)
}
if err != nil {
ERROR.Println(CLI, err.Error())
Expand Down

0 comments on commit 2d3b04d

Please sign in to comment.