Repository navigation
Conversation
BlockRequest._unref() set queued = false but left the request in replicator._queued, which is only drained while a peer is connected. On a core with no peers, every block request that timed out or was cancelled stayed in the queue until the core closed, leaking one BlockRequest per timed-out get. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
On a core with no peers, run gets that time out and assert that the replication queue is empty afterwards. Without the fix, each timed-out request stays in replicator._queued until the core closes. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
[Low impact] The PR appears safe to merge. SummaryRemoves cancelled block requests from the replication queue in shared cleanup passes, even when no peer is connected.
Reviews (5) · Last reviewed commit: "Assert the queue bound between compactio..." · Reviewed by Greptile |
Review feedback: indexOf + splice made each unreference O(n) in the queue length, so mass cancellation became quadratic. Stale entries are now counted and the queue is compacted in a single amortized pass from _queueBlock once they dominate, keeping each unreference O(1). A connected peer's sweep still drops stale entries as before. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Review feedback: the test accepted any error, so it could pass without exercising the timeout path. Now matches REQUEST_TIMEOUT, runs 100 timed-out requests, and asserts the queue retains at most the amortization bound (17) instead of all of them. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
… linger Review feedback: compaction waited for a later _queueBlock call, so a batch of requests that all timed out together (or a closing session) stayed in _queued until some future read. The amortized single-pass compaction now runs from _unref itself: still O(1) per unreference (one pass per 16+ stale entries), but cleanup no longer depends on later reads or a connected peer. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Adds a 40-request batch that all times out at once, so the test also covers cleanup when no later read triggers it. Fails against the previous revision (whole batch retained), passes now. The bound tightens to 16, matching the compaction threshold. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
The compaction pass filtered before the request being cancelled was marked, so that entry survived every pass and went uncounted; sequential timeouts could push the queue one past the bound. Mark it first so the pass drops it too. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Tracks the largest the queue grows across the whole run instead of only checking at the end. Sequential timeouts used to peak one past the bound between passes; now covered. Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Author
|
Could a maintainer review this change to remove timed-out block requests from the replication queue? Please let me know if there are concerns with the approach or specific changes needed to move it forward. Thanks. |
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.
Fixes #893
BlockRequest._unref()setqueued = falsebut left the request inreplicator._queued, and the only place that array is drained is the peer update loop, which needs a connected peer. On a core with no peers, every block request that timed out or was cancelled stayed in_queueduntil the core closed - one retainedBlockRequestper timed-outget, which the issue measures at ~3 GB of heap growth in a week for a process polling mostly-offline cores.The current revision marks each cancelled request before compacting the queue from
BlockRequest._unref(). Compaction is amortized rather than splicing once per cancellation: once more than 16 stale entries dominate the queue, a single pass removes them. This bounds retained timed-out requests to 16 in the regression scenario; it does not promise an empty queue after every timeout.The current regression performs 100 sequential timed-out gets with no connected peer, then a concurrent batch of 40. It checks
REQUEST_TIMEOUTand the maximum observed queue length between compaction passes, asserting that it stays at most 16. This supersedes the original five-request/empty-queue test description.Original validation (before the subsequent compaction revisions): the new test against both the unfixed and fixed code,
test/basic.js, plusprettier --checkandlunteon the changed files. One caveat: the fulltest/replicate.jsfile OOMs on my 1 GB test box at the pre-existing "one missing block, big core (slow)" test, so the new test also ran standalone; the change itself is confined toBlockRequest._unref().