Skip to content

Commit ea84c35

Browse files
gbn: Ensure we always handle Pong Tick events
If we have awaited a sync after sending the previous ping, both the pingTicker and pongTicker may have ticked when waiting to sync. In that case, we need to ensure that the pongTicker gets prioritized, which this commit ensures.
1 parent 73b69f0 commit ea84c35

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gbn/gbn_conn.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,26 @@ func (g *GoBackNConn) sendPacketsForever() error {
413413
continue
414414

415415
case <-g.pingTicker.Ticks():
416+
// If we have expected a sync after sending the previous
417+
// ping, both the pingTicker and pongTicker may have
418+
// ticked when waiting to sync. In that case, we can't
419+
// be sure which of the signals we receive over first in
420+
// the above select. We therefore need to check if the
421+
// pong ticker has ticked here to ensure that it get's
422+
// prioritized over the ping ticker.
423+
select {
424+
case <-g.pongTicker.Ticks():
425+
return errKeepaliveTimeout
426+
default:
427+
}
416428

417429
// Start the pong timer.
418430
g.pongTicker.Reset()
419431
g.pongTicker.Resume()
420432

433+
// Also reset the ping timer.
434+
g.pingTicker.Reset()
435+
421436
g.log.Tracef("Sending a PING packet")
422437

423438
packet = &PacketData{

0 commit comments

Comments
 (0)