Skip to content

Commit

Permalink
If c.options.Dialer was nil this caused a panic.
Browse files Browse the repository at this point in the history
Only an issue if ClientOptions is manually created.
  • Loading branch information
MattBrittan committed Dec 28, 2021
1 parent 44f71c7 commit 721bf9f
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 721bf9f

Please sign in to comment.