File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
projects/client/RabbitMQ.Client/src/client/impl Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -1079,16 +1079,23 @@ protected void MaybeStopHeartbeatTimers()
1079
1079
1080
1080
private void MaybeDisposeTimer ( ref Timer timer )
1081
1081
{
1082
- if ( timer != null )
1082
+ // capture the timer to reduce chance of a null ref exception
1083
+ var captured = timer ;
1084
+ if ( captured != null )
1083
1085
{
1084
1086
try
1085
1087
{
1086
- timer . Change ( Timeout . Infinite , Timeout . Infinite ) ;
1087
- timer . Dispose ( ) ;
1088
+ captured . Change ( Timeout . Infinite , Timeout . Infinite ) ;
1089
+ captured . Dispose ( ) ;
1090
+ timer = null ;
1088
1091
}
1089
1092
catch ( ObjectDisposedException )
1090
1093
{
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
1092
1099
}
1093
1100
}
1094
1101
}
You can’t perform that action at this time.
0 commit comments