From 7907950a5416d4ead665b968be4036b6ffb700a5 Mon Sep 17 00:00:00 2001 From: Sandy Kellagher Date: Wed, 7 Dec 2022 16:19:12 +0000 Subject: [PATCH] Fix for #3682: do not delay PINGs for GATEWAY or solicited LEAF connections, to ensure failover of leaf node connections --- server/client.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/client.go b/server/client.go index 9e79c848a2c..97a051069e2 100644 --- a/server/client.go +++ b/server/client.go @@ -4547,19 +4547,20 @@ func (c *client) processPingTimer() { var sendPing bool - // 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. pingInterval := c.srv.getOpts().PingInterval if c.kind == GATEWAY { pingInterval = adjustPingIntervalForGateway(pingInterval) - sendPing = true } now := time.Now() needRTT := c.rtt == 0 || now.Sub(c.rttStart) > DEFAULT_RTT_MEASUREMENT_INTERVAL - // Do not delay PINGs for GATEWAY connections. - if c.kind != GATEWAY { + // Do not delay PINGs for GATEWAY or spoke LEAF connections. + if 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 { @@ -4568,6 +4569,7 @@ func (c *client) processPingTimer() { sendPing = true } } + if sendPing { // Check for violation if c.ping.out+1 > c.srv.getOpts().MaxPingsOut {