Skip to content

Commit bb86c21

Browse files
Ignore exceptions that may arise when disposing timers
1 parent 85890a4 commit bb86c21

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
@@ -985,15 +985,22 @@ public void HeartbeatWriteTimerCallback(object state)
985985

986986
protected void MaybeStopHeartbeatTimers()
987987
{
988-
if(_heartbeatReadTimer != null)
989-
{
990-
_heartbeatReadTimer.Change(Timeout.Infinite, Timeout.Infinite);
991-
_heartbeatReadTimer.Dispose();
992-
}
993-
if(_heartbeatWriteTimer != null)
988+
MaybeDisposeTimer(_heartbeatReadTimer);
989+
MaybeDisposeTimer(_heartbeatWriteTimer);
990+
}
991+
992+
private void MaybeDisposeTimer(Timer timer)
993+
{
994+
if (timer != null)
994995
{
995-
_heartbeatWriteTimer.Change(Timeout.Infinite, Timeout.Infinite);
996-
_heartbeatWriteTimer.Dispose();
996+
try
997+
{
998+
timer.Change(Timeout.Infinite, Timeout.Infinite);
999+
timer.Dispose();
1000+
} catch (ObjectDisposedException ignored)
1001+
{
1002+
// we are shutting down, ignore
1003+
}
9971004
}
9981005
}
9991006

0 commit comments

Comments
 (0)