Skip to content

feat(storage/s3): make S3 socket timeout configurable#233

Open
devunt wants to merge 1 commit intofalcondev-oss:devfrom
penxle:patch/s3-socket-timeout-env
Open

feat(storage/s3): make S3 socket timeout configurable#233
devunt wants to merge 1 commit intofalcondev-oss:devfrom
penxle:patch/s3-socket-timeout-env

Conversation

@devunt
Copy link
Copy Markdown

@devunt devunt commented Apr 28, 2026

Problem

The S3 client uses a hardcoded socketTimeout: 3000 (ms), introduced in d682bc0 ("perf: reduce memory usage by using node streams") together with stream-based downloads.

Because this timeout applies to the GetObject body socket, any pause longer than 3s in pumpPartsToStreams (lib/storage.ts) — caused by backpressure from either the response stream or the merge upload (mergerStream, partSize: 5MB, queueSize: 1) — aborts the in-flight S3/R2 socket with ECONNRESET. The handler has already streamed the headers, so Nitro then surfaces an unhandled H3Error: aborted followed by ERR_HTTP_HEADERS_SENT.

This is reproducible on R2 with non-trivial caches: the very first download of any cache entry always proxies through the server (since mergedAt is null until the merge finishes), and 3s of stalled read while backpressure resolves is easy to hit.

Fix

Expose STORAGE_S3_SOCKET_TIMEOUT_MS so deployments hitting this can raise the limit without forking. Default raised to 10000 to give backpressure pauses more headroom on first-download proxy paths.

Notes

  • Single-line behavior change in lib/storage.ts; new env entry in lib/schemas.ts.
  • No changes needed to docs/values; users only override this when they need to tune it further.

Comment thread .github/workflows/release-penxle.yml Outdated
Comment thread lib/schemas.ts Outdated
The hardcoded socketTimeout: 3000 (introduced in d682bc0 along with
stream-based downloads) aborts in-flight R2/S3 GetObject body sockets
whenever the response stream is paused for >3s by backpressure from
either the client response or the merge upload, surfacing as
ECONNRESET on /download/<id>.

Expose STORAGE_S3_SOCKET_TIMEOUT_MS so deployments hitting this can
raise it without forking. Default raised to 10000 to give backpressure
pauses more headroom on first-download proxy paths.
@devunt devunt force-pushed the patch/s3-socket-timeout-env branch from 3a972b0 to b00f196 Compare April 29, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants