Skip to content

Commit

Permalink
Merge pull request #854 from bollhals/simplify.missed.heartbeat
Browse files Browse the repository at this point in the history
simplify missed heartbeat recognition

(cherry picked from commit ef01562)
  • Loading branch information
lukebakken authored and michaelklishin committed May 27, 2020
1 parent 56bd745 commit 9f0cdf8
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ internal sealed class Connection : IConnection
//
// Heartbeats
//

private TimeSpan _heartbeat = TimeSpan.Zero;
private TimeSpan _heartbeatTimeSpan = TimeSpan.FromSeconds(0);
private int _missedHeartbeats = 0;
private int _missedHeartbeats;
private bool _heartbeatDetected;

private Timer _heartbeatWriteTimer;
private Timer _heartbeatReadTimer;
private readonly AutoResetEvent _heartbeatRead = new AutoResetEvent(false);

private Task _mainLoopTask;

Expand Down Expand Up @@ -615,12 +614,9 @@ public void MainLoopIteration()
}
}

public void NotifyHeartbeatListener()
private void NotifyHeartbeatListener()
{
if (_heartbeat != TimeSpan.Zero)
{
_heartbeatRead.Set();
}
_heartbeatDetected = true;
}

public void NotifyReceivedCloseOk()
Expand Down Expand Up @@ -847,13 +843,14 @@ public void HeartbeatReadTimerCallback(object state)
{
if (!_closed)
{
if (!_heartbeatRead.WaitOne(0))
if (_heartbeatDetected)
{
_missedHeartbeats++;
_heartbeatDetected = false;
_missedHeartbeats = 0;
}
else
{
_missedHeartbeats = 0;
_missedHeartbeats++;
}

// We check against 8 = 2 * 4 because we need to wait for at
Expand Down Expand Up @@ -921,7 +918,7 @@ public void HeartbeatWriteTimerCallback(object state)
}
}

void MaybeStopHeartbeatTimers()
private void MaybeStopHeartbeatTimers()
{
NotifyHeartbeatListener();
_heartbeatReadTimer?.Dispose();
Expand Down

0 comments on commit 9f0cdf8

Please sign in to comment.