Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/worker/storage: Fix sync deadlock
Commit 2fdfd28 introduced a possibility of the storage round syncing process to deadlock when an unfortunate series of events occur in specific order. Assume the following happens, in order: 1. Round X has just completed syncing and has been applied, so lastFullyAppliedRound has been updated to X and all metadata about round X has been removed from syncingRounds and hashCache. Since the round has not yet been finalized, cachedLastRound still points to X-1. 2. A new incoming block for round X+1 appears. 3. The code checks what needs to be synced and starts with cachedLastRound which still points to round X-1 (because round X has not yet been applied). Because sync metadata of round X have been removed, it assumes that round X is not yet synced so it starts syncing it by queuing sync requests and adding new metadata to the top of the syncingRounds heap. 4. Round X is finalized, so cachedLastRound is updated to X. Since the top of the sync management loop checks if lastFullyAppliedRound + 1 is at the top of the heap this leads to a deadlock. The top item contains metadata for round X while the management loop is waiting for X+1. This commit fixes the issue by using lastFullyAppliedRound in the incoming block handler instead of cachedLastRound.
- Loading branch information