@@ -225,6 +225,8 @@ func (ls *LedgerState) handleEventBlockfetchBlock(e BlockfetchEvent) error {
225225 e ,
226226 )
227227 // Update busy time in order to detect fetch timeout
228+ ls .chainsyncBlockfetchBusyTimeMutex .Lock ()
229+ defer ls .chainsyncBlockfetchBusyTimeMutex .Unlock ()
228230 ls .chainsyncBlockfetchBusyTime = time .Now ()
229231 return nil
230232}
@@ -576,7 +578,10 @@ func (ls *LedgerState) blockfetchRequestRangeStart(
576578 return fmt .Errorf ("request block range: %w" , err )
577579 }
578580 // Reset blockfetch busy time
581+ ls .chainsyncBlockfetchBusyTimeMutex .Lock ()
579582 ls .chainsyncBlockfetchBusyTime = time .Now ()
583+ ls .chainsyncBlockfetchBusyTimeMutex .Unlock ()
584+
580585 // Create our blockfetch done signal channels
581586 ls .chainsyncBlockfetchReadyChan = make (chan struct {})
582587 ls .chainsyncBlockfetchBatchDoneChan = make (chan struct {})
@@ -589,8 +594,12 @@ func (ls *LedgerState) blockfetchRequestRangeStart(
589594 case <- time .After (500 * time .Millisecond ):
590595 }
591596 // Clear blockfetch busy flag on timeout
597+ ls .chainsyncBlockfetchBusyTimeMutex .Lock ()
598+ busyTime := ls .chainsyncBlockfetchBusyTime
599+ ls .chainsyncBlockfetchBusyTimeMutex .Unlock ()
600+
592601 if time .Since (
593- ls . chainsyncBlockfetchBusyTime ,
602+ busyTime ,
594603 ) > blockfetchBusyTimeout {
595604 ls .blockfetchRequestRangeCleanup (true )
596605 ls .config .Logger .Warn (
0 commit comments