Fix websocket connect timeout
This commit is contained in:
parent
01d78a1e5c
commit
87ff01ac68
|
@ -19,10 +19,13 @@ type WebsocketTransport struct {
|
||||||
func (t *WebsocketTransport) Connect() error {
|
func (t *WebsocketTransport) Connect() error {
|
||||||
t.ctx = context.Background()
|
t.ctx = context.Background()
|
||||||
|
|
||||||
|
if t.Config.ConnectTimeout > 0 {
|
||||||
ctx, cancel := context.WithTimeout(t.ctx, time.Duration(t.Config.ConnectTimeout)*time.Second)
|
ctx, cancel := context.WithTimeout(t.ctx, time.Duration(t.Config.ConnectTimeout)*time.Second)
|
||||||
|
t.ctx = ctx
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
}
|
||||||
|
|
||||||
wsConn, _, err := websocket.Dial(ctx, t.Config.Address, nil)
|
wsConn, _, err := websocket.Dial(t.ctx, t.Config.Address, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewConnError(err, true)
|
return NewConnError(err, true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue