Repository navigation
Description
Problem
HttpApi can now stream in both directions: StreamUint8Array and StreamNdjson request payloads (#9575), and StreamSse, StreamNdjson and StreamUint8Array responses. With default server settings, two runtime timeouts end these streams early. Neither is mentioned in the HttpApi docs or in the server layers' JSDoc.
Node: requestTimeout, 300 seconds by default. Node's http.Server limits how long it takes to receive the whole request. A streamed upload, or a two-way streaming session, that runs past five minutes gets a 408 and the connection is closed.
NodeHttpServer.layer(() => createServer({ requestTimeout: 1000, connectionsCheckingInterval: 100 }), { port: 0 })
// endpoint: payload StreamUint8Array; the client uploads 30 chunks, 100 ms apart
// => HttpClientError: Decode error (408 POST .../upload)Bun: idleTimeout, 10 seconds by default. Bun.serve closes a connection when no data has moved for 10 seconds, so an event feed that is quiet for that long gets closed.
BunHttpServer.layer({ port: 0 })
// handler: Stream.make(1, 2), then one more element after 12 s
// Bun: [Bun.serve]: request timed out after 10 seconds. Pass `idleTimeout` to configure.
// client: HttpClientError: ... The socket connection was closed unexpectedlyBoth defaults are sensible for ordinary requests, and short tests never reach them. That is why this only shows up in production.
Proposal
- Document both timeouts in the streaming sections of the HttpApi docs and in the
NodeHttpServer.layerandBunHttpServer.layerJSDoc, with the trade-offs:- Node:
createServer({ requestTimeout: 0 })or a larger value. This applies to every route, because Node has no per-request setting. - Bun:
idleTimeoutup to 255 seconds or0, or make the stream send something more often.
- Node:
- Bun has a per-request
server.timeout(request, seconds), butBunHttpServerkeeps the Bun server private (BunHttpServer.ts:433). Expose a way to call it, so a single streaming endpoint can relax the idle timeout without relaxing it for the whole server.
Scope
In scope:
- Docs for Node and Bun.
- The per-request timeout for Bun.
Out of scope:
- Changing the runtimes' defaults.
- Deno, which hasn't been checked.
- Client timeouts. The undici client already sets no body timeout.
Open questions
- Should
StreamSsehave an optional keep-alive interval that sends a comment line? It would also stop idle proxies from closing the connection.
Activity