Skip to content

Commit 2e8ff5d

Browse files
bollhalslukebakken
authored andcommitted
simplify missed heartbeat recognition
1 parent d99db81 commit 2e8ff5d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ internal sealed class Connection : IConnection
8787
private TimeSpan _heartbeat = TimeSpan.Zero;
8888
private TimeSpan _heartbeatTimeSpan = TimeSpan.FromSeconds(0);
8989
private int _missedHeartbeats = 0;
90+
private int _heartbeatCounter;
91+
private int _lastHeartbeat;
9092

9193
private Timer _heartbeatWriteTimer;
9294
private Timer _heartbeatReadTimer;
93-
private readonly AutoResetEvent _heartbeatRead = new AutoResetEvent(false);
9495

9596
private Task _mainLoopTask;
9697

@@ -617,10 +618,7 @@ public void MainLoopIteration()
617618

618619
public void NotifyHeartbeatListener()
619620
{
620-
if (_heartbeat != TimeSpan.Zero)
621-
{
622-
_heartbeatRead.Set();
623-
}
621+
_heartbeatCounter++;
624622
}
625623

626624
public void NotifyReceivedCloseOk()
@@ -847,7 +845,7 @@ public void HeartbeatReadTimerCallback(object state)
847845
{
848846
if (!_closed)
849847
{
850-
if (!_heartbeatRead.WaitOne(0))
848+
if (_lastHeartbeat == _heartbeatCounter)
851849
{
852850
_missedHeartbeats++;
853851
}
@@ -856,6 +854,8 @@ public void HeartbeatReadTimerCallback(object state)
856854
_missedHeartbeats = 0;
857855
}
858856

857+
_lastHeartbeat = _heartbeatCounter;
858+
859859
// We check against 8 = 2 * 4 because we need to wait for at
860860
// least two complete heartbeat setting intervals before
861861
// complaining, and we've set the socket timeout to a quarter

0 commit comments

Comments
 (0)