Skip to content

Commit b212368

Browse files
Ignore exceptions that may arise when disposing timers
1 parent 3aa42f7 commit b212368

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,15 +1092,22 @@ public void HeartbeatWriteTimerCallback(object state)
10921092

10931093
protected void MaybeStopHeartbeatTimers()
10941094
{
1095-
if(_heartbeatReadTimer != null)
1096-
{
1097-
_heartbeatReadTimer.Change(Timeout.Infinite, Timeout.Infinite);
1098-
_heartbeatReadTimer.Dispose();
1099-
}
1100-
if(_heartbeatWriteTimer != null)
1095+
MaybeDisposeTimer(_heartbeatReadTimer);
1096+
MaybeDisposeTimer(_heartbeatWriteTimer);
1097+
}
1098+
1099+
private void MaybeDisposeTimer(Timer timer)
1100+
{
1101+
if (timer != null)
11011102
{
1102-
_heartbeatWriteTimer.Change(Timeout.Infinite, Timeout.Infinite);
1103-
_heartbeatWriteTimer.Dispose();
1103+
try
1104+
{
1105+
timer.Change(Timeout.Infinite, Timeout.Infinite);
1106+
timer.Dispose();
1107+
} catch (ObjectDisposedException ignored)
1108+
{
1109+
// we are shutting down, ignore
1110+
}
11041111
}
11051112
}
11061113

0 commit comments

Comments
 (0)