File tree 1 file changed +10
-4
lines changed
projects/client/RabbitMQ.Client/src/client/impl
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -1114,18 +1114,24 @@ protected void MaybeStopHeartbeatTimers()
1114
1114
1115
1115
private void MaybeDisposeTimer ( ref Timer timer )
1116
1116
{
1117
- if ( timer != null )
1117
+ // capture the timer to reduce chance of a null ref exception
1118
+ var captured = timer ;
1119
+ if ( captured != null )
1118
1120
{
1119
1121
try
1120
1122
{
1121
- timer . Change ( Timeout . Infinite , Timeout . Infinite ) ;
1122
- timer . Dispose ( ) ;
1123
+ captured . Change ( Timeout . Infinite , Timeout . Infinite ) ;
1124
+ captured . Dispose ( ) ;
1123
1125
timer = null ;
1124
1126
}
1125
- catch ( ObjectDisposedException ignored )
1127
+ catch ( ObjectDisposedException )
1126
1128
{
1127
1129
// we are shutting down, ignore
1128
1130
}
1131
+ catch ( NullReferenceException )
1132
+ {
1133
+ // this should be very rare but could occur from a race condition
1134
+ }
1129
1135
}
1130
1136
}
1131
1137
You can’t perform that action at this time.
0 commit comments