Continue on aborted in block sorter - #1617
Open
yashnevatia wants to merge 2 commits into
Open
Conversation
product-security-plaid-production
Bot
requested review from
huangzhen1997 and
ilija42
August 28, 2026 15:27
Contributor
|
👋 yashnevatia, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
Contributor
📊 API Diff Results
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log Poller deadlock:
blocksSorternever closesoutBlocksSummary
When a block fetch is aborted, the log poller's block sorter can shut down without
closing its output channel, leaving the consumer in
processBlocksRangeblockedforever on a receive that will never complete. The backfill/replay stalls with no
timeout and no error.
The pipeline
BackfillForAddresses(loader.go) wires the whole thing together:getSlotsToFetchresolves the[fromSlot, toSlot]range down to the subset ofslots that actually contain transactions for the watched addresses.
scheduleBlocksFetchingspawns onegetBlockJobper slot and returns theunorderedBlockschannel. Each job pushes its fetched block into that channel.When all jobs are done,
scheduleBlocksFetchingcallsclose(blocks).newBlocksSorter(unorderedBlocks, …)takes that channel as itsinBlocksandre-emits the blocks in slot order on
outBlocks, which is whatprocessBlocksRangeconsumes.So
unorderedBlocksis the hand-off: the sorter reads it, and its closure is thesignal that no more blocks are coming.
Where it breaks
1.
inBlocksclosing is the "we're done" signalIn
readBlocks(blocks_sorter.go), whenscheduleBlocksFetchingcloses the channel:Closing
receivedNewBlockis what tellswriteOrderedBlocksto do its final flushand wind down.
2.
writeOrderedBlocksonly closesoutBlocksif the queue is emptyThe intent is "only signal completion once every expected block has been emitted."
The queue still holds every slot that hasn't been emitted yet — so if anything is
left over,
close(p.outBlocks)is skipped, and the goroutine returns. Nothingelse ever closes
outBlocks.3.
flushReadyBlocksreturns early on an aborted block, leaving the queue non-emptygetBlockJob.Abortdoesn't skip the send — it pushes a block withAborted = trueinto
unorderedBlocks, so the aborted block lands in the sorter'sreadyBlocks.readNextReadyBlockhas already removed the head element before theAbortedcheck.So when the head block is aborted,
flushReadyBlockspops it and returns immediately,without draining the blocks still queued behind it.
The deadlock, end to end
receivedNewBlockhas capacity 1 andreadBlocksonly does a best-effortnon-blocking send, so notifications coalesce — many queued blocks can be
represented by a single wakeup.
ok == false),flushReadyBlockspops an aborted head blockand returns early with the queue still non-empty.
writeOrderedBlocksseesqueue.Len() != 0, skipsclose(p.outBlocks), and returns.processBlocksRange(case block, ok := <-blocks:) blocks foreveron a channel that is never written to or closed again — no timeout, no error.
Fix
Skip the aborted block and keep draining instead of returning:
With the queue fully drained on every flush, the final pass always sees
queue.Len() == 0andclose(p.outBlocks)fires, so the consumer terminates cleanly.