fix: validate timeout is non-negative finite number#7444
Open
Nicknamess96 wants to merge 1 commit intoaxios:v1.xfrom
Open
fix: validate timeout is non-negative finite number#7444Nicknamess96 wants to merge 1 commit intoaxios:v1.xfrom
Nicknamess96 wants to merge 1 commit intoaxios:v1.xfrom
Conversation
Reject negative, Infinity, and -Infinity timeout values early in dispatchRequest with a clear AxiosError (ERR_BAD_OPTION_VALUE) instead of letting them propagate to Node.js internals where they cause a confusing RangeError. Fixes axios#7428
Author
|
Friendly ping — this adds validation to reject negative or non-finite timeout values that currently cause silent failures. Tests pass. Happy to address any feedback. |
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
Validates
config.timeoutearly indispatchRequestbefore any adapter processes it. Rejects negative,Infinity, and-Infinityvalues with a clearAxiosError(ERR_BAD_OPTION_VALUE) instead of letting them reach Node.js internals where they cause a confusingRangeError.Fixes #7428
Motivation
Passing
timeout: -1000crashes with:This is confusing because the stack trace points to Node.js internals, not to the axios config. The fix catches this early with:
Approach
Validation is placed in
dispatchRequest.jsrather than in individual adapters so that all adapters (http, xhr, fetch) benefit from the check. Non-numeric values (objects, non-numeric strings) are intentionally left to adapter-level handling for backward compatibility (the http adapter usesparseIntto parse string timeouts like'250').Changes
lib/core/dispatchRequest.js: AddedvalidateTimeout()that runs before adapter dispatchtest/unit/core/dispatchRequest.js: 10 new test cases covering negative, Infinity, -Infinity, NaN, zero, null, undefined, positive, string, and negative string timeoutsTest plan
npm run test:node)npm run test:eslint)'250'still workSummary by cubic
Validates config.timeout in dispatchRequest and rejects negative and infinite values with a clear AxiosError (ERR_BAD_OPTION_VALUE). Prevents confusing Node RangeError and applies consistently across all adapters.
Bug Fixes
Testing
Written for commit 4e1d5b1. Summary will update on new commits.