fix(lib-node): destroy streamed error response body to avoid socket leak#35
Open
BatLeDev wants to merge 1 commit into
Open
fix(lib-node): destroy streamed error response body to avoid socket leak#35BatLeDev wants to merge 1 commit into
BatLeDev wants to merge 1 commit into
Conversation
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.
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.
A response requested with
responseType: 'stream'whose status fails the request'svalidateStatusrejects with the body still an unconsumedReadablebound to its keepalive socket. The error interceptor dropped that reference (delete error.response.data) without draining it, so the socket was never released. AftermaxSockets(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 axiostimeout).Fix:
destroy()the stream before deleting the reference.Why now: surfaced in
@data-fair/processingsv6, 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.destroy()only adds socket cleanup, no behavior change for callers.