Skip to content

Commit 322c704

Browse files
authored
Always perform "last read" check in heartbeat when HeartbeatConsistencyChecks is enabled (#2795)
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.
1 parent 654859f commit 322c704

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

docs/ReleaseNotes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Current package versions:
77
| [![StackExchange.Redis](https://img.shields.io/nuget/v/StackExchange.Redis.svg)](https://www.nuget.org/packages/StackExchange.Redis/) | [![StackExchange.Redis](https://img.shields.io/nuget/vpre/StackExchange.Redis.svg)](https://www.nuget.org/packages/StackExchange.Redis/) | [![StackExchange.Redis MyGet](https://img.shields.io/myget/stackoverflow/vpre/StackExchange.Redis.svg)](https://www.myget.org/feed/stackoverflow/package/nuget/StackExchange.Redis) |
88

99
## Unreleased
10-
No pending unreleased changes.
10+
11+
- Fix: PhysicalBridge: Always perform "last read" check in heartbeat when `HeartbeatConsistencyChecks` is enabled ([#2795 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2795))
1112

1213
## 2.8.14
1314

src/StackExchange.Redis/PhysicalBridge.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ internal void OnHeartbeat(bool ifConnectedOnly)
652652
// so if we have an empty unsent queue and a non-empty sent queue, test the socket.
653653
KeepAlive();
654654
}
655-
else if (timedOutThisHeartbeat > 0
655+
656+
// 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
657+
if (timedOutThisHeartbeat > 0
656658
&& tmp.LastReadSecondsAgo * 1_000 > (tmp.BridgeCouldBeNull?.Multiplexer.AsyncTimeoutMilliseconds * 4))
657659
{
658660
// 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

0 commit comments

Comments
 (0)