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