Repository navigation
Description
Follow-up to #292. These are the S3 connection, merge and download-lifecycle fixes I have been running on a patched 9.8.0, rebased onto dev (6ae06c2) with regression tests. Like #292, the repo only accepts PRs from collaborators, so each is a branch in my fork (stacked where noted). Every test listed fails or times out on dev and passes with the fix. Branch links go to the fork's review copies, which ran CI and a Codex review.
1. S3 socket pool size, and the agent for http:// endpoints
Branch: perf/s3-socket-pool (review copy)
The S3 client uses one hard-coded 50-socket keep-alive agent and passes it only as httpsAgent. NodeHttpHandler picks the agent by endpoint scheme, so http:// endpoints (MinIO, RustFS, in-cluster gateways) silently use the SDK default agent, and nobody can size the pool for their concurrency. Adds STORAGE_S3_MAX_SOCKETS (default 50, minimum 2) for both agents.
2. Streaming merges deadlock the shared S3 pool
Branch: perf/s3-pool-split, stacked on 1 (review copy)
A streaming merge (the first restore of an unmerged entry, or a streaming eager merge) holds a part GetObject that backpressure pauses, while lib-storage waits in the same pool for a socket to upload the merged object. Once concurrent merges reach maxSockets, every socket is a paused GET waiting for a socket that never frees. No restore or merge completes, merge leases renew forever, and the HeadObject behind every cache lookup queues indefinitely, so every cache step on every runner times out.
With a pool of 4 and 4 concurrent cold restores, 0 of 4 complete in 21 s and a HeadObject sent 1 s in gets no answer within 15 s. With separate read, write and control pools all 4 finish in 124–144 ms; 4 sockets with 8 restores and 16 with 16 behave the same way (shared pool: nothing completes; split: everything under 0.75 s). I hit this under real CI load, not only in tests; raising maxSockets only moves the threshold.
The branch gives reads, writes and control requests (HEAD/LIST/DELETE) their own clients and agents, with STORAGE_S3_CONTROL_MAX_SOCKETS (default 16) and a connection-wait limit for control requests (STORAGE_S3_CONTROL_QUEUE_TIMEOUT_MS, default 5000).
3. No global limit on concurrent merges
Branch: perf/merge-concurrency-cap (review copy)
Every first restore of an unmerged entry, and every finalize with EAGER_MERGE, starts a merge with no global limit; each holds sockets, a lease and buffers for its whole duration, and a lazy merge is paced by the client. Adds MAX_CONCURRENT_MERGES (default 16). Past the cap a restore streams the parts, exactly as when another worker holds the merge lease, and a later download merges.
4. Downloads whose client stopped reading are never closed
Branch: perf/download-idle-timeout, stacked on #292's pump fix (review copy)
Neither the HTTP server nor the download route bounds a response in progress. A client that stays connected but stops reading parks the pipe forever: it holds a storage socket, renews the reader lease, and on a first restore stalls the merge it paces. Adds DOWNLOAD_IDLE_TIMEOUT_MS (default 5 min, 0 disables), refreshed on every chunk, for whole, Range and first-restore downloads.
5. A client that leaves before storage answers pins the storage read
Branch: fix/download-client-gone (review copy)
If the client disconnects while storage.download() is still waiting (for example a GetObject queued for a socket), the body arrives for an already-closed response. pipeline rejects with ERR_STREAM_UNABLE_TO_PIPE without taking ownership of the source, and the route rethrows without destroying it, so the storage socket and reader lease stay pinned for the life of the process (reproduced on Node 26.12.1 on top of #282 and #291). The route now checks res.destroyed || res.closed before piping and destroys the body on every error exit.
6. Metrics for pools, merges, leases and downloads
Branch: perf/storage-metrics, stacked on 1–5 and the pump fix (review copy)
Pool starvation and merge contention are invisible on /metrics today; the deadlock in 2 shows up only in S3 SDK debug logs. Adds low-cardinality series: S3 pool sockets/queue/max and socket wait, per-command S3 outcome/latency/retries, merges (finished, skipped, in progress, oldest age), lease rows, download outcomes and lookup latency. Nothing is recorded per chunk.
7. The Postgres startup probe client is never released
Branch: fix/postgres-probe-release (review copy)
getDatabase checks out a client to validate the connection and never releases it, so the pool runs one client short and db.destroy() would hang on pool.end(). One line; covered by the Postgres suite.
Overlap with #288: the Rust server has no bounded pool, so 1, 2 and 5 do not apply there, and it already handles the pump case. It also has no merge cap (3), no idle timeout (4) and none of the metrics in 6; those may be worth carrying over. Separate README "Resource limits" sections in 1–4 will conflict trivially if they land separately.
CI note: fork CI is green on every branch. On sqlite runs, tests/range-download.test.ts occasionally fails in ~20 ms with SqliteError: database is locked from createReaderLease (seen on three branches, each green on rerun). download() reads and then writes inside a deferred transaction while the test process and the server share the SQLite file, so SQLite returns SQLITE_BUSY immediately instead of waiting. It looks pre-existing; I can open a separate issue if useful.
Activity