Repository navigation
fix(http): stop per-socket error listener from retaining the installing request's context (memory leak) - #11091
Merged
jasonsaayman merged 3 commits intoAug 4, 2026
Conversation
…ng request's context The once-per-socket 'error' listener introduced in v1.15.2 (axios#10780 fix) is an inline closure created inside dispatchHttpRequest. Because it is never removed, its scope chain pins the entire adapter scope of whichever request first touched the socket — including the settled response promise (full response body) and buffered chunks — for the lifetime of every pooled keep-alive socket. On busy services with warm agent pools this retains multiple MB per socket (GBs at fleet scale), growing with socket churn. Hoist the listener to a module-scope function that reads the active request via this[kAxiosCurrentReq] (EventEmitter binds `this` to the socket), so it captures no per-request context. Error semantics are unchanged.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
Greptile SummaryThis change updates the Node HTTP adapter so pooled keep-alive sockets use one module-scoped error listener while each socket tracks its currently active request. Focused runtime checks confirmed that socket errors are delivered only to the active request after pooled-socket reassignment, and that separate sockets share the listener without cross-request failure handling. The two targeted Node HTTP adapter regression tests passed. Confidence Score: 5/5Reviews (1): Last reviewed commit: "fix(http): validate shared socket error ..." | Re-trigger Greptile |
This was referenced Sep 10, 2026
3 tasks done
markharding
pushed a commit
to futo-org/Harbor
that referenced
this pull request
Oct 16, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [axios](https://axios-http.com) ([source](https://github.com/axios/axios)) | [`1.18.1` → `1.20.0`](https://renovatebot.com/diffs/npm/axios/1.18.1/1.20.0) |  |  | --- >⚠️ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/99) for more information. --- ### Release Notes <details> <summary>axios/axios (axios)</summary> ### [`v1.20.0`](https://github.com/axios/axios/releases/tag/v1.20.0) [Compare Source](axios/axios@v1.19.0...v1.20.0) #### v1.20.0 — August 19, 2026 This release hardens runtime option handling, adds RFC 9110 status-code aliases, fixes Node.js and XHR reliability issues, and refreshes project tooling and documentation. ####⚠️ Breaking Changes & Deprecations - HTTP Status Naming: Added ContentTooLarge (413) and UnprocessableContent (422), while retaining PayloadTooLarge and UnprocessableEntity as backward-compatible deprecated aliases. ([#​11082](axios/axios#11082)) #### 🔒 Security Fixes - Runtime Option Handling: Hardened behavioral configuration reads against shared and foreign prototype pollution and normalized unsafe interceptor replacement objects. This also clarifies Fetch redirect and custom implementation behavior, HTTP/2 DNS and proxy handling, CIDR-based NO_PROXY matching, and malformed data URI rejection; see the PR for documented compatibility effects. ([#​11141](axios/axios#11141)) #### 🐛 Bug Fixes - Interceptor Lifecycle: Prevented unbounded handler-array growth by trimming trailing ejected interceptors without changing iteration semantics, and kept interceptor operations safe when the public handlers field is nullish. ([#​11087](axios/axios#11087), [#​11118](axios/axios#11118)) - Request Error Preservation: Prevented custom Error.prepareStackTrace implementations that return non-string values from replacing the original request failure with an unrelated TypeError. ([#​11109](axios/axios#11109)) - XHR Reliability: Navigation-canceled requests now reject with ECONNABORTED instead of resolving with status 0, while successful downloads flush their final progress callback during the live loadend dispatch. ([#​11094](axios/axios#11094), [#​11121](axios/axios#11121)) - Node.js Socket Memory: Removed request-context retention from per-socket error listeners, preventing completed response data from being pinned for the lifetime of pooled keep-alive sockets. ([#​11091](axios/axios#11091)) - Core Methods and HTTP Errors: Prevented structural method-header buckets from leaking into outgoing headers, standardized invalid DNS lookup and httpVersion failures as AxiosError.ERR_BAD_OPTION_VALUE, and corrected the timeoutErrorMessage merge strategy. ([#​11096](axios/axios#11096)) #### 🔧 Maintenance & Chores - Dependencies: Updated fast-uri, postcss, js-yaml, mocha, development-tooling groups, and GitHub Actions dependencies. ([#​11092](axios/axios#11092), [#​11098](axios/axios#11098), [#​11099](axios/axios#11099), [#​11106](axios/axios#11106), [#​11107](axios/axios#11107), [#​11122](axios/axios#11122), [#​11123](axios/axios#11123), [#​11126](axios/axios#11126), [#​11127](axios/axios#11127), [#​11133](axios/axios#11133), [#​11140](axios/axios#11140), [#​11143](axios/axios#11143), [#​11144](axios/axios#11144)) - Documentation: Applied the v1.19.0 documentation updates, added the missing fs import to the README stream example, introduced localized global search, and repaired the interceptor test link. ([#​11101](axios/axios#11101), [#​11113](axios/axios#11113), [#​11097](axios/axios#11097), [#​11119](axios/axios#11119)) - Sponsorship: Updated sponsorship links and data and added ScrapingBee as a sponsor. ([#​11124](axios/axios#11124), [#​11136](axios/axios#11136), [#​11137](axios/axios#11137)) - CI and Release: Switched ESM smoke tests to locked dependencies and synchronized package and runtime version metadata for v1.20.0. ([#​11128](axios/axios#11128), [#​11152](axios/axios#11152)) #### 🌟 New Contributors We are thrilled to welcome our new contributors. Thank you for helping improve axios: - [@​yens1](https://github.com/yens1) ([#​11109](axios/axios#11109)) - [@​Sasireddy001](https://github.com/Sasireddy001) ([#​11113](axios/axios#11113)) - [@​ari-token-security](https://github.com/ari-token-security) ([#​11094](axios/axios#11094)) - [@​timothyokooboh](https://github.com/timothyokooboh) ([#​11097](axios/axios#11097)) - [@​gi9439041-png](https://github.com/gi9439041-png) ([#​11119](axios/axios#11119)) - [@​Hashim1999164](https://github.com/Hashim1999164) ([#​11082](axios/axios#11082)) - [@​v-dev-cl](https://github.com/v-dev-cl) ([#​11091](axios/axios#11091)) - [@​r0h1tb](https://github.com/r0h1tb) ([#​11118](axios/axios#11118)) - [@​ostapondo](https://github.com/ostapondo) ([#​11121](axios/axios#11121)) Full Changelog (<axios/axios@v1.19.0...v1.20.0>) ### [`v1.19.0`](https://github.com/axios/axios/blob/HEAD/CHANGELOG.md#v1190--July-22-2026) [Compare Source](axios/axios@v1.18.1...v1.19.0) This release raises the form-data security floor, adds configuration and type-system capabilities, and fixes NO_PROXY matching, interceptor errors, progress reporting, and serialization edge cases. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE2NC41IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1808
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
Since v1.15.2, the http adapter installs a once-per-socket
'error'listener (handleSocketError, the fix for #10780's listener accumulation). That listener is an inline closure created insidedispatchHttpRequestand is never removed — so via its scope chain it retains the entire adapter scope of whichever request first touched the socket for the socket's whole lifetime: the settled response promise (reactions_or_result→ the full response body), the buffered body chunks,boundSockets, timers.With keep-alive agent pools that stay warm (long-running services), every pooled socket permanently pins one complete response (~body size × 2: string on-heap + chunk buffers off-heap). On our scraper fleet (agentkeepalive pools up to 600 sockets, ~3 MB HTML responses) this retained multiple GB per process and OOM-killed pods continuously. The leak grows with socket churn and is invisible to handle counts — heap and external memory grow ~1:1 while active handles stay flat, and a full GC reclaims nothing.
Affects v1.15.2 through current v1.x head (verified in 1.16.0, 1.17.0, 1.18.1 and this branch).
Evidence (heap snapshot from production, axios 1.17.0)
Retainer path for a 3.2 MB retained response string:
A snapshot of one process showed 1046 Socket/TLSSocket objects in heap vs ~295 live socket handles, 766 retained
IncomingMessages, and hundreds of MB of response strings +JSArrayBufferData, all rooted inhandleSocketErrorclosures on pooled or dead sockets.Repro
Standalone script (node --expose-gc repro.js) — measures post-GC memory while the pool is warm
Results (30-socket warm pool, 3 MB bodies, post-GC):
The retained memory frees only when the sockets die — confirming the retainer is the per-socket listener, not the requests.
Fix
Hoist the listener to a module-scope function that reads the active request via
this[kAxiosCurrentReq](EventEmitterinvokes listeners withthisbound to the emitter, i.e. the socket). It captures no per-request context; the once-per-socket install guard, thekAxiosCurrentReqswap, and the error semantics (destroy the currently-active request) are unchanged.🤖 Generated with Claude Code
Summary by cubic
Fixes a memory leak in the Node
httpadapter by switching the per-socket'error'listener to a shared module-scope function. Behavior is unchanged; socket errors still destroy only the active request.Description
'error'handler to a module-scopehandleSocketErrorand installed it once per socket.this[kAxiosCurrentReq]and callsdestroy(err).kAxiosSocketListenerguard and existing error semantics.Docs
/docs/under the Nodehttpadapter about the keep-alive memory retention fix inv1.x; no user action is required.Testing
'error'listener across different sockets.Semantic version impact
Written for commit 4b13a79. Summary will update on new commits.