Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 1e36e6c

Browse files
committed
much harsher heartbeat handling
1 parent b80e497 commit 1e36e6c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ func (g *GatewayConnection) startWorkers() error {
922922
receivedAck: true,
923923
sequence: new(int64),
924924
onNoAck: func() {
925-
g.log(LogError, "No heartbeat ack received since sending last heartbeast, reconnecting...")
925+
g.log(LogError, "No heartbeat ack received since sending last heartbeast, reconnecting... ip: %s", g.conn.RemoteAddr)
926926
err := g.ReconnectUnlessClosed(false)
927927
if err != nil {
928928
g.log(LogError, "Failed reconnecting to the gateway: %v", err)

wsapi.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,16 @@ func (wh *wsHeartBeater) Run(interval time.Duration) {
158158
case <-ticker.C:
159159

160160
wh.Lock()
161+
timeSinceAck := time.Since(wh.lastAck)
161162
hasReceivedAck := wh.receivedAck
162163
wh.receivedAck = false
163-
wh.missedAcks++
164-
missed := wh.missedAcks
165-
166-
wh.lastSend = time.Now()
167164
wh.Unlock()
168165

169-
if !hasReceivedAck && wh.onNoAck != nil && missed > 4 {
166+
if !hasReceivedAck && timeSinceAck >= interval {
170167
wh.onNoAck()
168+
} else {
169+
wh.SendBeat()
171170
}
172-
173-
wh.SendBeat()
174171
case <-wh.stop:
175172
return
176173
}

0 commit comments

Comments
 (0)