Repository navigation
fix: cap concurrent Merges and close downloads whose client stopped reading - #300
Merged
Merged
Conversation
Every first restore of an unmerged entry and, with EAGER_MERGE, every finalize started a Merge with no global limit. Each Merge holds storage connections, a Merge Lease and stream buffers for its whole duration, and a lazy Merge is paced by the restoring client's read speed. A burst of first restores or of finalizes therefore grew Merges, sockets and memory without bound. Start a Merge only while fewer than MAX_CONCURRENT_MERGES (default 16) run in this process. Beyond that, startMerge returns false: a restore streams the parts directly, exactly as when another worker holds the Merge Lease, an Eager Merge is left to the first download, and a later download merges the entry. The slot is reserved before the first await, so concurrent callers cannot overshoot it. tests/merge-concurrency.test.ts covers a first restore and an Eager Merge beyond the limit. Signed-off-by: Rui Chen <rui@chenrui.dev>
Node's HTTP server has no idle timeout for a response in progress and the download route set none. A client that stays connected but stops reading parks the pipe forever: the backend read keeps its storage socket, the Storage Reader Lease keeps renewing, and on the first restore of an unmerged entry the Merge it paces never finishes and keeps its Merge Lease. Each such client permanently removes one socket from the storage pool. Destroy the download when no bytes have moved for DOWNLOAD_IDLE_TIMEOUT_MS (default 300000, 0 disables). The timer is refreshed on every chunk, so slow but progressing clients are unaffected. It covers whole and Range responses and the first restore of an unmerged entry, whose Merge keeps going after the client's side of the tee is closed. tests/proxy-backpressure.test.ts parks a client after the first chunk of a 200, a 206 and an unmerged first restore, and checks that the storage read is released, the response closed, and the Merge completed. Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Release the Merge slot in one finally, cap DOWNLOAD_IDLE_TIMEOUT_MS at setTimeout's maximum, describe the timeout by what it measures, and drop tests that repeat coverage of the merge pump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Name the idle timeout error like the other route errors and cover a slow download staying open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LouisHaftmann
force-pushed
the
fix/merge-cap-download-idle-timeout
branch
from
October 25, 2026 11:53
eb59f6a to
f328e3a
Compare
This was referenced Oct 29, 2026
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.
📝 Summary
Stacked on #296. Two more resource leaks from #293:
EAGER_MERGE, starts a Merge that holds sockets, a Merge Lease and buffers for its whole duration. A burst of first restores exhausts them. NowMAX_CONCURRENT_MERGES(default 16) caps Merges per process; past it a restore streams the parts, exactly as when another worker holds the Merge Lease, and a later download merges.DOWNLOAD_IDLE_TIMEOUT_MS(default 5 min,0disables) closes it.Both settings are in the Helm chart (
config.maxConcurrentMerges,config.downloadIdleTimeoutMs). ADR-0009 now records that Eager Merges share the cap and fall back to a lazy Merge past it.✅ Verification
Each new test fails on the #296 branch without the fix:
merge-concurrency: a first restore beyond the cap still merges, somergedAtis setproxy-backpressureidle timeout: a stalled client never gets its storage read released (20 s timeout)proxy-backpressureslow download: with the timer not refreshed on each chunk, a download that keeps moving is cut offThe matrix ran before the last commit, which only renames the error class, adds the slow-download test and edits docs;
proxy-backpressurewas re-run after it.type-check,eslint,prettier --checkandhelm templatepass.🔍 Reviews
Not fixed:
res.setTimeoutinstead of a timer: the socket timeout would carry over to later keep-alive requests on the same socket; the timer is scoped to this response.merge-concurrencyandmerge-socket-pool: the signatures differ, small gain.downloadhelper: it would passundefinedwhere a stream is expected.startMerge: one for a Merge that never started, one when it ends.startMergeguard.write()throwing synchronously would leak a slot: same ondevfor the lease renewal timer, and every writer is async.🔗 Issues
Refs #293 (items 3 and 4). Item 6 is now #297; #293 can close once this and #296 merge.
💥 Merge danger
Door: two-way
No migrations; both settings can be raised or disabled (
DOWNLOAD_IDLE_TIMEOUT_MS=0) without a redeploy of code.Blast Radius: downloads
EAGER_MERGE=true, finalizes past the cap leave the entry to merge on first download.🤖 Generated with Claude Code