From e3007c5e7f56637d5b407c5738b552a0009f06c7 Mon Sep 17 00:00:00 2001 From: Corbin Phelps Date: Thu, 28 Jul 2022 14:14:15 -0400 Subject: [PATCH] Don't call OnConnectFailed when failed to connect during shutdown (#113) Fixes #111 Once `Stop()` is called on the websocket client we don't call `OnConnectFailed` handler if a dial fails. Tested this fix on a system that was repeatedly showing the `OnConnectFailed` handler called during shutdown. --- client/wsclient.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/wsclient.go b/client/wsclient.go index 468ec0f4..1ac0de3a 100644 --- a/client/wsclient.go +++ b/client/wsclient.go @@ -121,7 +121,7 @@ func (c *wsClient) tryConnectOnce(ctx context.Context) (err error, retryAfter sh var resp *http.Response conn, resp, err := c.dialer.DialContext(ctx, c.url.String(), c.requestHeader) if err != nil { - if c.common.Callbacks != nil { + if c.common.Callbacks != nil && !c.common.IsStopping() { c.common.Callbacks.OnConnectFailed(err) } if resp != nil {