fix(http): ensure timeout works correctly with maxRedirects=0#10657
fix(http): ensure timeout works correctly with maxRedirects=0#10657NETIZEN-11 wants to merge 3 commits intoaxios:v1.xfrom
Conversation
Fixes axios#6801 When maxRedirects=0, axios bypasses follow-redirects and uses native http/https modules. Previously, timeout was not properly enforced in this flow, causing requests to hang indefinitely when encountering unresponsive servers. Changes: - Enhanced error handler to prevent double error emission - Added socket-level timeout configuration for early-stage hangs - Improved request timeout handler to use req.destroy() directly - Ensured consistent error messages: 'timeout of Xms exceeded' - Always use ETIMEDOUT error code for timeout errors The fix ensures timeout is properly enforced regardless of maxRedirects value and prevents requests from hanging indefinitely. Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
- There is a concrete regression risk in
lib/adapters/http.js: timeout handling now ignorestimeoutErrorMessageandtransitional.clarifyTimeoutError, which can change runtime error behavior for consumers. - Because this is a medium-severity (6/10) issue with high confidence (9/10) and affects documented adapter semantics, the merge risk is moderate rather than minimal.
- Pay close attention to
lib/adapters/http.js- timeout error messaging/clarification behavior may be inconsistent with other adapters and expected docs.
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:910">
P2: HTTP adapter timeout logic now ignores `timeoutErrorMessage` and `transitional.clarifyTimeoutError`, causing behavioral regression and inconsistency with documented/other adapter behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Added support for config.timeoutErrorMessage for custom timeout messages - Added support for config.transitional.clarifyTimeoutError - Ensures consistency with XHR adapter behavior - Fixes regression where timeout error messaging was hardcoded
|
Thanks for the patch. I'm going to close this one. The underlying issue is real, but smaller than the description suggests, and the diff has some problems that I'd want fixed before reworking the approach. I tried reproducing #6801 against the current v1.x HEAD with two cases: a stalling TCP server (accepts the connection, never writes) and an unreachable host (192.0.2.1, TEST-NET-1). In both cases, the request always settled. So "the promise never settles" doesn't match what v1.x is doing today. There is still a real bug, just narrower: with On the diff itself, a few things would need to change:
Closing in favour of a focused fix tracked in the new issue. |
Description
Fixes #6801
This PR resolves an issue where requests would hang indefinitely when
maxRedirects = 0and the target server is unresponsive. In such cases, Axios failed to enforce the configured timeout, resulting in no error being thrown and the request never settling.Problem
When
maxRedirects = 0, Axios bypasses thefollow-redirectslibrary and directly uses Node.js nativehttp/httpsmodules. In this execution path:timeoutwas not consistently enforcedcatchblock would never executeAdditionally, when
maxRedirects > 0, timeout-related failures could produce inconsistent error messages such as"aborted"instead of a proper timeout error.Solution
This PR introduces a robust and consistent timeout handling mechanism in
lib/adapters/http.js, ensuring correct behavior across all redirect configurations.Key Improvements
Consistent Timeout Enforcement
Timeout is now always applied regardless of the
maxRedirectsvalue.Socket-Level Timeout Handling
A timeout is attached to the underlying socket to handle cases where the connection stalls before the request is fully established.
Improved Request Timeout Logic
req.destroy()with a properAxiosErrorinstead of relying onabort()timeout of <X>ms exceededETIMEDOUTSafe Error Handling
isDoneflag) to prevent multiple error emissionsChanges
req.destroy()Testing
The following scenarios have been verified:
maxRedirects = 0maxRedirects > 0timeout of Xms exceeded)ETIMEDOUTBackward Compatibility
This change is fully backward compatible. It does not modify the public API and only improves internal timeout handling behavior.
Related Issues
Closes #6801
Summary by cubic
Enforces timeouts in the Node
http/httpsadapter even whenmaxRedirects = 0, preventing hangs on unresponsive servers. Also supportstimeoutErrorMessageandtransitional.clarifyTimeoutErrorfor consistent timeout errors.Description
req.setTimeoutand socketsetTimeout; usereq.destroy()on timeout.timeoutErrorMessageandtransitional.clarifyTimeoutErrorfor parity with XHR.Testing
maxRedirects = 0and> 0without hanging.timeoutErrorMessageis used when provided.transitional.clarifyTimeoutError.Written for commit 98f841f. Summary will update on new commits.