-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Issue 4014: simplified ping handling / deferral based on rece… #4015
Closed
sandykellagher
wants to merge
1
commit into
nats-io:main
from
Lawo-Ext:Issue_4014_simplified_ping_handling
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,9 +286,10 @@ type rrTracking struct { | |
|
||
// Struct for PING initiation from the server. | ||
type pinfo struct { | ||
tmr *time.Timer | ||
last time.Time | ||
out int | ||
tmr *time.Timer | ||
lastRxPing time.Time | ||
lastRxMsg time.Time | ||
out int | ||
} | ||
|
||
// outbound holds pending data for a socket. | ||
|
@@ -1309,6 +1310,7 @@ func (c *client) readLoop(pre []byte) { | |
// Activity based on interest changes or data/msgs. | ||
if c.in.msgs > 0 || c.in.subs > 0 { | ||
c.last = last | ||
c.ping.lastRxMsg = last | ||
} | ||
|
||
if n >= cap(b) { | ||
|
@@ -2196,7 +2198,7 @@ func (c *client) processPing() { | |
|
||
// Record this to suppress us sending one if this | ||
// is within a given time interval for activity. | ||
c.ping.last = time.Now() | ||
c.ping.lastRxPing = time.Now() | ||
|
||
// If not a CLIENT, we are done. Also the CONNECT should | ||
// have been received, but make sure it is so before proceeding | ||
|
@@ -4555,32 +4557,21 @@ func (c *client) processPingTimer() { | |
|
||
c.Debugf("%s Ping Timer", c.kindString()) | ||
|
||
var sendPing bool | ||
|
||
pingInterval := c.srv.getOpts().PingInterval | ||
if c.kind == GATEWAY { | ||
pingInterval = adjustPingIntervalForGateway(pingInterval) | ||
} | ||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing the write is most important over potential long haul or multi-hope networks. So even if we have received something we may need to write, so prefer this logic remains. |
||
sendPing = true | ||
// If we have had receive 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.ping.lastRxMsg); delta < pingInterval && !needRTT { | ||
c.Debugf("Delaying PING due to receive traffic %v ago", delta.Round(time.Second)) | ||
} else if delta := now.Sub(c.ping.lastRxPing); delta < pingInterval && !needRTT { | ||
c.Debugf("Delaying PING due to remote ping %v ago", delta.Round(time.Second)) | ||
} 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)) | ||
} else { | ||
sendPing = true | ||
} | ||
} | ||
|
||
if sendPing { | ||
// Check for violation | ||
if c.ping.out+1 > c.srv.getOpts().MaxPingsOut { | ||
c.Debugf("Stale Client Connection - Closing") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these not be combined? I think they are doing the same which is recording inbound activity only.