Skip to content

Commit

Permalink
Alternative fix for issue 4014, where we always send pings on ROUTER …
Browse files Browse the repository at this point in the history
…connections, updating c.ping.last timestamp on receiving client data
  • Loading branch information
sandykellagher committed Apr 4, 2023
1 parent 94278e7 commit 5c5f773
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions server/client.go
Expand Up @@ -1307,8 +1307,10 @@ func (c *client) readLoop(pre []byte) {
c.mu.Lock()

// Activity based on interest changes or data/msgs.
// Also update last receive activity for ping sender
if c.in.msgs > 0 || c.in.subs > 0 {
c.last = last
c.ping.last = last
}

if n >= cap(b) {
Expand Down Expand Up @@ -4564,17 +4566,14 @@ func (c *client) processPingTimer() {
now := time.Now()
needRTT := c.rtt == 0 || now.Sub(c.rttStart) > DEFAULT_RTT_MEASUREMENT_INTERVAL

// Do not delay PINGs for GATEWAY or spoke LEAF connections.
if c.kind == GATEWAY || c.isSpokeLeafNode() {
// Do not delay PINGs for ROUTER, GATEWAY or spoke LEAF connections.
if c.kind == ROUTER || c.kind == GATEWAY || c.isSpokeLeafNode() {
sendPing = true
} else {
// If we have had activity within the PingInterval then
// there is no need to send a ping. This can be client data
// or if we received a ping from the other side.
if delta := now.Sub(c.last); delta < pingInterval && !needRTT {
c.Debugf("Delaying PING due to client activity %v ago", delta.Round(time.Second))
} else if delta := now.Sub(c.ping.last); delta < pingInterval && !needRTT {
c.Debugf("Delaying PING due to remote ping %v ago", delta.Round(time.Second))
// If we received client data or a ping from the other side within the PingInterval,
// then there is no need to send a ping.
if delta := now.Sub(c.ping.last); delta < pingInterval && !needRTT {
c.Debugf("Delaying PING due to remote client data or ping %v ago", delta.Round(time.Second))
} else {
sendPing = true
}
Expand Down

0 comments on commit 5c5f773

Please sign in to comment.