Skip to content

Commit

Permalink
Update c.ping.last timestamp on receiving client data
Browse files Browse the repository at this point in the history
  • Loading branch information
sandykellagher committed Apr 4, 2023
1 parent fc37eb5 commit 41ff5b9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 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 @@ -4568,10 +4570,10 @@ func (c *client) processPingTimer() {
if c.kind == ROUTER || c.kind == GATEWAY || c.isSpokeLeafNode() {
sendPing = true
} else {
// If we received a ping from the other side within the PingInterval then
// there is no need to send a ping.
// 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 ping %v ago", delta.Round(time.Second))
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 41ff5b9

Please sign in to comment.