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()
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 }
You can’t perform that action at this time.
0 commit comments