Skip to content

Commit

Permalink
PhysicalBrdige: Always perform "last read" check in heartbeat
Browse files Browse the repository at this point in the history
When we have slowly adding things to the heartbeat (originally intended just to send data to keep connections alive) like detecting connection health, the if/else has gotten more complicated. With the addition of `HeartbeatConsistencyChecks`, we prevented some fall throughs to later checks which means that if that option is enabled, we were no longer detecting dead sockets as intended.

This is a tactical fix for the combination, but I think overall we should look at refactoring how this entire method works because shoehorning these things into the original structure/purpose has been problematic several times.
  • Loading branch information
NickCraver committed Sep 10, 2024
1 parent 654859f commit fb47f20
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/StackExchange.Redis/PhysicalBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ internal void OnHeartbeat(bool ifConnectedOnly)
// so if we have an empty unsent queue and a non-empty sent queue, test the socket.
KeepAlive();
}
else if (timedOutThisHeartbeat > 0

// This is an "always" check - we always want to evaluate a dead connection from a non-responsive sever regardless of the need to heartbeat above
if (timedOutThisHeartbeat > 0
&& tmp.LastReadSecondsAgo * 1_000 > (tmp.BridgeCouldBeNull?.Multiplexer.AsyncTimeoutMilliseconds * 4))
{
// If we've received *NOTHING* on the pipe in 4 timeouts worth of time and we're timing out commands, issue a connection failure so that we reconnect
Expand Down

0 comments on commit fb47f20

Please sign in to comment.