From 721bf9fa7789cf99251c4cd40fc15764dcc77773 Mon Sep 17 00:00:00 2001 From: Matt Brittan Date: Tue, 28 Dec 2021 15:37:52 +1300 Subject: [PATCH] If c.options.Dialer was nil this caused a panic. Only an issue if ClientOptions is manually created. --- client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 5cea7219..06ee61aa 100644 --- a/client.go +++ b/client.go @@ -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())