From 87ff01ac6863acbc99c69120006839ffa91f0070 Mon Sep 17 00:00:00 2001
From: Wichert Akkerman <wichert@wiggy.net>
Date: Sat, 12 Oct 2019 17:50:00 +0200
Subject: [PATCH] Fix websocket connect timeout

---
 websocket_transport.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/websocket_transport.go b/websocket_transport.go
index 5564a5e..a526fc4 100644
--- a/websocket_transport.go
+++ b/websocket_transport.go
@@ -19,10 +19,13 @@ type WebsocketTransport struct {
 func (t *WebsocketTransport) Connect() error {
 	t.ctx = context.Background()
 
-	ctx, cancel := context.WithTimeout(t.ctx, time.Duration(t.Config.ConnectTimeout)*time.Second)
-	defer cancel()
+	if t.Config.ConnectTimeout > 0 {
+		ctx, cancel := context.WithTimeout(t.ctx, time.Duration(t.Config.ConnectTimeout)*time.Second)
+		t.ctx = ctx
+		defer cancel()
+	}
 
-	wsConn, _, err := websocket.Dial(ctx, t.Config.Address, nil)
+	wsConn, _, err := websocket.Dial(t.ctx, t.Config.Address, nil)
 	if err != nil {
 		return NewConnError(err, true)
 	}