Skip to content

fix(lib-node): destroy streamed error response body to avoid socket leak#35

Open
BatLeDev wants to merge 1 commit into
mainfrom
fix-node-axios-stream-socket-leak
Open

fix(lib-node): destroy streamed error response body to avoid socket leak#35
BatLeDev wants to merge 1 commit into
mainfrom
fix-node-axios-stream-socket-leak

Conversation

@BatLeDev
Copy link
Copy Markdown
Member

@BatLeDev BatLeDev commented May 29, 2026

A response requested with responseType: 'stream' whose status fails the request's validateStatus rejects with the body still an unconsumed Readable bound to its keepalive socket. The error interceptor dropped that reference (delete error.response.data) without draining it, so the socket was never released. After maxSockets (8) such errors against a host, its agentkeepalive pool is exhausted and every subsequent request to that host hangs forever (the wait for a free socket isn't covered by the axios timeout).

Fix: destroy() the stream before deleting the reference.

Why now: surfaced in @data-fair/processings v6, the first consumer to stream tarball downloads from the registry — its 403/404 plugin-download paths (permission / missing-plugin tests) leaked a socket each, eventually wedging all registry downloads until an API restart.

Regression risks:

  • destroy() is guarded by _readableState, so it only runs on a Readable body; non-stream error bodies are untouched.
  • The reference was already being deleted immediately after, so no consumer could read the body post-interceptor — destroy() only adds socket cleanup, no behavior change for callers.

A response with responseType:'stream' whose status fails validateStatus
leaves its body as an unconsumed Readable bound to a keepalive socket.
The error interceptor dropped the reference without draining it, leaking
the socket; after maxSockets such errors the host pool is exhausted and
every later request to that host hangs. Destroy the stream before delete.
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.

1 participant