Skip to content

Commit 3d355ec

Browse files
Merge branch 'stable'
Conflicts: projects/client/RabbitMQ.Client/src/client/impl/Connection.cs
2 parents a2feb24 + 6f82824 commit 3d355ec

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,16 +1079,23 @@ protected void MaybeStopHeartbeatTimers()
10791079

10801080
private void MaybeDisposeTimer(ref Timer timer)
10811081
{
1082-
if (timer != null)
1082+
// capture the timer to reduce chance of a null ref exception
1083+
var captured = timer;
1084+
if (captured != null)
10831085
{
10841086
try
10851087
{
1086-
timer.Change(Timeout.Infinite, Timeout.Infinite);
1087-
timer.Dispose();
1088+
captured.Change(Timeout.Infinite, Timeout.Infinite);
1089+
captured.Dispose();
1090+
timer = null;
10881091
}
10891092
catch (ObjectDisposedException)
10901093
{
1091-
timer = null;
1094+
// we are shutting down, ignore
1095+
}
1096+
catch(NullReferenceException)
1097+
{
1098+
// this should be very rare but could occur from a race condition
10921099
}
10931100
}
10941101
}

0 commit comments

Comments
 (0)