Skip to content

Commit

Permalink
Merge pull request #899 from iotaledger/fix/warpsync-deadlock
Browse files Browse the repository at this point in the history
Fix WarpSync deadlock
  • Loading branch information
piotrm50 authored Apr 15, 2024
2 parents 44acb4d + 5b3d91e commit 6d0a4e3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/protocol/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ func newWarpSync(protocol *Protocol) *WarpSync {
protocol.Chains.WithInitializedEngines(func(chain *Chain, engine *engine.Engine) (shutdown func()) {
return chain.WarpSyncMode.OnUpdate(func(_ bool, warpSyncModeEnabled bool) {
if warpSyncModeEnabled {
engine.Workers.WaitChildren()
engine.Reset()
// We need to wait for all workers of the engine to finish and reset in a separate worker,
// since otherwise we're locking downstream (c.LatestSyncedSlot, c.chains.LatestSeenSlot, c.OutOfSyncThreshold of the chain).
// Which in turn can lead to a deadlock where the engine can't update the LatestSyncedSlot.
// By running it in the warpsync's single worker we also make sure that the engine is reset before
// actually warp syncing/processing new slots.
c.workerPool.Submit(func() {
engine.Workers.WaitChildren()
engine.Reset()
})
}
})
})
Expand Down

0 comments on commit 6d0a4e3

Please sign in to comment.