@@ -28,6 +28,7 @@ public class PeerRefresher : IPeerRefresher, IAsyncDisposable
2828 private ( Hash256 headBlockhash , Hash256 headParentBlockhash , Hash256 finalizedBlockhash ) _lastBlockhashes = ( Keccak . Zero , Keccak . Zero , Keccak . Zero ) ;
2929 private readonly ITimer _refreshTimer ;
3030 private readonly ILogger _logger ;
31+ private bool _disposed ;
3132
3233 public PeerRefresher ( IPeerDifficultyRefreshPool syncPeerPool , ITimerFactory timerFactory , ILogManager logManager )
3334 {
@@ -40,6 +41,7 @@ public PeerRefresher(IPeerDifficultyRefreshPool syncPeerPool, ITimerFactory time
4041
4142 public void RefreshPeers ( Hash256 headBlockhash , Hash256 headParentBlockhash , Hash256 finalizedBlockhash )
4243 {
44+ if ( _disposed ) return ;
4345 _lastBlockhashes = ( headBlockhash , headParentBlockhash , finalizedBlockhash ) ;
4446 TimeSpan timePassed = DateTime . UtcNow - _lastRefresh ;
4547 if ( timePassed > _minRefreshDelay )
@@ -79,6 +81,10 @@ Hash256 finalizedBlockhash
7981 {
8082 await RefreshPeerForFcu ( syncPeer , headBlockhash , headParentBlockhash , finalizedBlockhash , delaySource . Token ) ;
8183 }
84+ catch ( OperationCanceledException )
85+ {
86+ if ( _logger . IsDebug ) _logger . Debug ( $ "Peer refresh timed out.") ;
87+ }
8288 catch ( Exception exception )
8389 {
8490 if ( _logger . IsError ) _logger . Error ( $ "Exception in peer refresh. This is unexpected. { syncPeer } ", exception ) ;
@@ -199,7 +205,11 @@ private static bool TryGetHeadAndParent(Hash256 headBlockhash, Hash256 headParen
199205
200206 public ValueTask DisposeAsync ( )
201207 {
202- _refreshTimer . Dispose ( ) ;
208+ if ( ! _disposed )
209+ {
210+ _disposed = true ;
211+ _refreshTimer . Dispose ( ) ;
212+ }
203213 return default ;
204214 }
205215}
0 commit comments