Skip to content

Commit 4e28826

Browse files
authored
fix: synchronize access to chainsyncBlockfetchBusyTime (#1198)
Signed-off-by: Chris Guiney <chris@guiney.net>
1 parent 4d8e6b8 commit 4e28826

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ledger/chainsync.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(

ledger/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ type LedgerState struct {
290290
metrics stateMetrics
291291
currentEra eras.EraDesc
292292
config LedgerStateConfig
293+
chainsyncBlockfetchBusyTimeMutex sync.Mutex // protects chainsyncBlockfetchBusyTime
293294
chainsyncBlockfetchBusyTime time.Time
294295
currentPParams lcommon.ProtocolParameters
295296
mempool MempoolProvider

0 commit comments

Comments
 (0)