Skip to content

Commit d794a48

Browse files
Clarify, start sending heartbeats immediately
Helps when heartbeat timeout is set to 1.
1 parent 006d541 commit d794a48

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,11 @@ public void MainLoopIteration()
701701
}
702702
}
703703

704+
// socket receive timeout is configured to be 1/2 of the heartbeat timeout
705+
// and the peer must be considered dead after two subsequent missed heartbeats:
706+
// terminate after 4 socket timeouts
707+
private const int SOCKET_TIMEOUTS_TO_CONSIDER_PEER_UNRESPONSIVE = 4;
708+
704709
protected void HandleIOException(Exception e)
705710
{
706711
// socket error when in negotiation, throw BrokerUnreachableException
@@ -711,9 +716,7 @@ protected void HandleIOException(Exception e)
711716
throw new BrokerUnreachableException(cfe);
712717
}
713718

714-
// socket receive timeout is configured to be 1/2 of the heartbeat timeout,
715-
// the peer must be considered dead after two subsequent missed heartbeats
716-
if (++m_missedHeartbeats >= 4)
719+
if (++m_missedHeartbeats >= SOCKET_TIMEOUTS_TO_CONSIDER_PEER_UNRESPONSIVE)
717720
{
718721
var description =
719722
String.Format("Peer missed 2 heartbeats with heartbeat timeout set to {0} seconds",
@@ -948,7 +951,7 @@ public void StartHeartbeatTimer()
948951
if (Heartbeat != 0)
949952
{
950953
_heartbeatWriteTimer = new Timer(HeartbeatWriteTimerCallback);
951-
_heartbeatWriteTimer.Change(m_heartbeatTimeSpan, m_heartbeatTimeSpan);
954+
_heartbeatWriteTimer.Change(TimeSpan.FromMilliseconds(0), m_heartbeatTimeSpan);
952955
}
953956
}
954957

0 commit comments

Comments
 (0)