From 7b67a9840567087f314f5e19f481aa673b3a2c0e Mon Sep 17 00:00:00 2001 From: diamondburned Date: Thu, 31 Dec 2020 23:01:38 -0800 Subject: [PATCH] Gateway: Prevent heartbeat reconnecting twice --- gateway/gateway.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gateway/gateway.go b/gateway/gateway.go index 0a1a6b9..8530963 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -360,9 +360,15 @@ func (g *Gateway) start(ctx context.Context) error { g.waitGroup.Done() // mark so Close() can exit. wsutil.WSDebug("Event loop stopped with error:", err) + // Bail if there is no error or if the error is an explicit close, as + // there might be an ongoing reconnection. + if err == nil || errors.Is(err, wsutil.ErrWebsocketClosed) { + return + } + // Only attempt to reconnect if we have a session ID at all. We may not // have one if we haven't even connected successfully once. - if err != nil && g.SessionID() != "" { + if g.SessionID() != "" { g.ErrorLog(err) g.Reconnect() }