fix(http): handle socket errors to prevent EPIPE crashes#10561
Closed
cyphercodes wants to merge 2 commits intoaxios:v1.xfrom
Closed
fix(http): handle socket errors to prevent EPIPE crashes#10561cyphercodes wants to merge 2 commits intoaxios:v1.xfrom
cyphercodes wants to merge 2 commits intoaxios:v1.xfrom
Conversation
Add error event handler to the request socket to catch errors like EPIPE that can crash the Node.js process when the connection is destroyed while the request body is still being written. Fixes axios#10558
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
- There is a concrete medium-severity risk in
lib/adapters/http.js: a per-requestsocket.on('error')listener is not removed, which can accumulate on keep-alive socket reuse. - Given the 6/10 severity with high confidence (9/10), this is likely to cause runtime warnings and potential memory/performance degradation under sustained traffic, so merge risk is moderate.
- Pay close attention to
lib/adapters/http.js- ensure socket error listeners are detached or otherwise bounded per request to prevent listener buildup.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/adapters/http.js">
<violation number="1" location="lib/adapters/http.js:878">
P2: Per-request `socket.on('error')` listener is never detached, causing listener accumulation on reused keep-alive sockets.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Change socket.on('error') to socket.once('error') in handleRequestSocket
to prevent listener accumulation on reused keep-alive sockets.
Fixes axios#10561
Contributor
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/adapters/http.js">
<violation number="1" location="lib/adapters/http.js:879">
P2: `socket.once('error')` is added per request on reused keep-alive sockets but never removed on successful completion, so listeners can accumulate until an error occurs.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| // Handle socket errors to prevent uncaught exceptions (e.g., EPIPE) | ||
| // Use once() to avoid listener accumulation on reused keep-alive sockets | ||
| socket.once('error', function handleSocketError(err) { |
Contributor
There was a problem hiding this comment.
P2: socket.once('error') is added per request on reused keep-alive sockets but never removed on successful completion, so listeners can accumulate until an error occurs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/adapters/http.js, line 879:
<comment>`socket.once('error')` is added per request on reused keep-alive sockets but never removed on successful completion, so listeners can accumulate until an error occurs.</comment>
<file context>
@@ -875,7 +875,8 @@ export default isHttpAdapterSupported &&
// Handle socket errors to prevent uncaught exceptions (e.g., EPIPE)
- socket.on('error', function handleSocketError(err) {
+ // Use once() to avoid listener accumulation on reused keep-alive sockets
+ socket.once('error', function handleSocketError(err) {
reject(AxiosError.from(err, null, config, req));
});
</file context>
Member
|
Closing in favour of #10662 |
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.
Problem
Failed requests can sometimes crash the Node.js process with EPIPE error when the server destroys the socket while the request body is still being written.
This issue was reported in #10558 where the following uncaught exception occurs:
Solution
Add an error event handler to the request socket in the HTTP adapter. This catches socket-level errors (like EPIPE, ECONNRESET) that occur after the socket is assigned but might not be caught by the request error handler alone.
Changes
lib/adapters/http.jsthat rejects the promise with an AxiosError when socket errors occurTesting
Impact
Critical bug fix - Prevents Node.js process crashes in production environments when dealing with unreliable connections or servers that close connections unexpectedly.
Fixes #10558
Summary by cubic
Handle socket errors in the Node.js HTTP adapter to prevent EPIPE/ECONNRESET crashes. Use socket.once to avoid listener leaks on keep‑alive sockets; requests now reject with
AxiosErrorinstead of crashing.Description
socket.once('error', ...)insidereq.on('socket', ...)inlib/adapters/http.jsAxiosError.from(err, null, config, req)once()prevents listener accumulation on reused keep‑alive socketsDocs
EPIPE,ECONNRESET) surface asAxiosErrorrejectionsTesting
AxiosErrorcarryingcodeEPIPE/ECONNRESETWritten for commit c13c943. Summary will update on new commits.