Repository navigation
fix: unstick S3 restores under load and stop repo-scoped deletes wiping every entry - #296
Merged
Merged
Conversation
`DELETE /management-api/cache-entries` accepted a `repoId` filter and documented it, but never applied it, so a delete filtered only by repository removed every cache entry of every repository. Apply it like the other filters. The Rust rewrite in #288 already fixes this; this is the same fix for the current TypeScript server. Signed-off-by: Rui Chen <rui@chenrui.dev>
getDatabase checks a client out of the pool to fail fast on bad connection settings and never released it. That client stays checked out for the life of the process, leaving the pool one connection short, and Kysely's destroy() (pool.end()) would wait for it forever. Signed-off-by: Rui Chen <rui@chenrui.dev>
The first download of an unmerged entry tees its parts into the client response and the background merge upload. A destroyed stream returns false from write() and never emits 'drain' (nor 'error' when destroyed without one), so the pump parks forever when: - the merge upload fails: `download()` destroys the merger stream, and the client's download stalls mid-body until the client times out; - the client hangs up while the pump waits on the merger: the next write to the destroyed response stream parks the pump, the merge never completes, and its lease keeps renewing. Either way the current part's backend read stays open (one S3 socket per occurrence), so enough of them fill the S3 socket pool. Wait for 'drain' or 'close', skip destroyed sinks, keep feeding the one that is still open, and stop reading once both are gone so `streamParts` destroys the current part stream. The regression tests fail on the previous pump with the filesystem and S3 drivers: the merge never settles after the client leaves, the client never finishes after the merge upload fails, and the part stream is never destroyed when both are gone. Signed-off-by: Rui Chen <rui@chenrui.dev>
`streamParts()` awaited `globalThis.gc()` after every part, and the image starts Node with `--expose-gc`, so every part of every unmerged restore and streaming merge ran a synchronous full mark-compact on the event loop. With ~1 MiB parts (BuildKit) that caps all concurrent first restores combined at roughly one part per GC pause, and the pause grows with the heap, so more concurrent restores make every one of them slower. Memory no longer depends on it: the upload route lets storage pace the body (#275) and the download route pipes with backpressure (#282), so the bytes in flight are bounded by stream high-water marks and become ordinary garbage that V8 collects incrementally. Remove both calls, the `--expose-gc` flag and the startup warning about it. Signed-off-by: Rui Chen <rui@chenrui.dev>
`lib/storage.ts` imported `@azure/storage-blob`, `@azure/identity` and `@google-cloud/storage` at the top level, so every server loaded all three SDKs whatever `STORAGE_DRIVER` said. Since the Azure Blob driver (#280) that adds about 40 MB of live heap to an idle S3 or filesystem server, and every GC cycle has to walk it. Import each SDK inside its adapter's `fromEnv`; only types stay as static imports. Signed-off-by: Rui Chen <rui@chenrui.dev>
…endpoints The S3 client's agent pool was hard-coded at 50 sockets, and the agent was passed only as `httpsAgent`. NodeHttpHandler picks the agent by endpoint scheme, so an http:// endpoint (MinIO, RustFS, an in-cluster gateway) silently fell back to the SDK's default agent and ignored the configured pool. Local tests and benchmarks against RustFS therefore never exercised the pool an https deployment uses. Add STORAGE_S3_MAX_SOCKETS (default 50, the previous value) and build both the http and the https agent from the same options. tests/s3-socket-pool.test.ts holds one GetObject body unread with a pool of one socket and checks that a second GetObject waits for it; against an http:// endpoint it did not wait before this change. Signed-off-by: Rui Chen <rui@chenrui.dev>
All S3 traffic shared one client and one agent pool. A streaming Merge (the first restore of an unmerged entry, or a streaming Eager Merge) holds a part GetObject open, paused by backpressure, while lib-storage waits in that 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: the pool deadlocks, Merge Leases renew forever, no Merge or restore completes, and every later S3 call queues behind them. That includes the HeadObject each cache lookup issues, which also waits behind every bulk transfer in the agent's FIFO queue even without a deadlock. Use one S3Client per kind of work: - reads: GetObject (and presigning) (STORAGE_S3_MAX_SOCKETS) - writes: PutObject, multipart uploads, UploadPartCopy compose (STORAGE_S3_MAX_SOCKETS) - control: HeadObject, HeadBucket, ListObjectsV2, DeleteObjects (STORAGE_S3_CONTROL_MAX_SOCKETS, default 16) Write-socket holders never wait on reads, and control requests hold a socket only briefly, so no wait cycle spans pools. The control client also sets connectionTimeout (STORAGE_S3_CONTROL_QUEUE_TIMEOUT_MS, default 5000), which bounds the wait for a socket plus the connect, so a starved lookup fails instead of hanging. tests/merge-socket-pool.test.ts runs as many concurrent first restores as pool sockets (4) against RustFS; with the shared pool it never finishes. tests/s3-socket-pool.test.ts checks that a HeadObject is answered while every data socket is held by an unread GetObject body. Signed-off-by: Rui Chen <rui@chenrui.dev>
… storage answers A client can give up on /download while its storage read is still waiting, for example a GetObject queued behind a saturated socket pool. The body then arrives for a response that is already closed. `pipeline` rejects a closed destination with ERR_STREAM_UNABLE_TO_PIPE before it takes ownership of the source, and the route rethrew without destroying it, so the body pinned its backend socket and the Storage Reader Lease for the life of the process. Enough of them fill the pool and every storage call queues. Check the response before piping and destroy the body if the client is gone, and destroy it on every error exit of the pipe as well. #282 and #291 already cover a client leaving mid-body. tests/download-client-gone.test.ts holds the storage read until the client has hung up, then checks that the backend socket and the reader lease are released; on Node 26.12.1 the socket stayed held before this change. Signed-off-by: Rui Chen <rui@chenrui.dev>
The error hook, the debug request/response hooks and the Results Passthrough logged `event.path` with its query string. Upload URLs are used by Azure Blob-style clients that put SAS-style parameters in the query, so those logs could record credentials. Log the path without its query string. Storage errors in the upload route are logged by the route and rethrown as a handled error, because Nitro logs unhandled errors with the full request URL. The request-logging hooks move from `plugins/setup.ts` into their own plugin so the test can drive them against the real upload route. Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the duplicate pre-pipe check in the download route (the catch already handles ERR_STREAM_UNABLE_TO_PIPE), import the Azure SDK where SAS signing uses it, rename loggedPath to pathWithoutQuery, expose the new S3 pool settings in the Helm chart, and let hangs fail as test timeouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 29, 2026
Closed
Closed
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
@chenrui333 reported a set of bugs from running the server under real CI load in #292–#295: restores that hang until every cache step times out, a management delete that ignores
repoIdand wipes every entry, and 9.9.0 loading all storage SDKs whatever the driver. They had fixes ready but couldn't open PRs here, so this cherry-picks their branches (authorship kept) plus a small round of review cleanup and two extra tests.DELETE /management-api/cache-entrieshonorsrepoIdinstead of deleting everythingdrainon a destroyed stream, so a client hangup or failed merge upload no longer parks it forever--expose-gc); about 10x first-restore throughput at 16 concurrentSTORAGE_S3_MAX_SOCKETS(default 50), applied tohttp://endpoints too, which previously got an unbounded default agentThe deadlock in #293.2:
New env vars are also exposed in the Helm chart (
config.storage.s3.maxSockets,controlMaxSockets,controlQueueTimeoutMs).✅ Verification
Every new test was run against
origin/devsource and fails there:dev):management-apidelete by repoId: fails, the other repo's entry is gonedownload-merge-sink-gone(3 tests): time out, the pump hangsdownload-client-gone: times out, the body is never destroyed and the reader lease staysdb-destroy(Postgres):db.destroy()hangsstorage-sdk-loading: loads@azure/identity,@azure/storage-blob,@google-cloud/storagewith the filesystem drivers3-socket-poolpool-size test: fails, the http endpoint ignores the pool sizemerge-socket-pool+ lookup HEAD (on S3 pool deadlock, unbounded merges and stalled downloads: fixes from a patched 9.8.0 #293.1 without the split): 4 concurrent first restores on a 4-socket pool deadlock (60 s timeout); a HEAD gets no answer while reads hold the pooltype-check,eslint,prettier --check,buildandhelm templatepass. #292.2 has no test: it's a perf change with nothing behavioral to assert; the benchmark is in #292.🔍 Reviews
Not fixed:
S3Clientsinterface kept: named and documented, inlining saves 5 lines.tests/setup.tsrepeating env defaults: itssatisfiesrequires them.try/catch: Nitro logs unhandled errors with the full URL itself.STORAGE_S3_MAX_SOCKETSminimum is 1, not 2 as S3 pool deadlock, unbounded merges and stalled downloads: fixes from a patched 9.8.0 #293 says: with split pools a single socket can't deadlock, and a test runs with 1.plugins/request-logging.ts: needed so the test can load them.🔗 Issues
Closes #292
Closes #295
Partially addresses #293 (1, 2, 5, 7) and #294 (2).
💥 Merge danger
Door: two-way
No migrations or data changes; every fix reverts cleanly.
Blast Radius: S3 deployments
S3 now opens up to 50 + 50 + 16 sockets instead of 50 shared, and
http://endpoints are bounded for the first time. Cache lookups that wait more than 5 s per attempt for a control socket now fail instead of hanging. The upload route turns storage failures into a 500 with a generic message.tests/range-download.test.tson sqlite can fail withdatabase is lockedfromcreateReaderLease.🤖 Generated with Claude Code