refactor: clean up composeSignals early-return structure#10844
Merged
jasonsaayman merged 3 commits intoMay 6, 2026
Conversation
Flips the main if-block to an early-return pattern to reduce nesting. Explicitly initializes aborted to false. Adds a guard clause in unsubscribe to avoid duplicate cleanup. Preserves the existing manual event-listener approach because AbortSignal.any() introduces event-loop timing differences that break fetch adapter stream-abort tests. Closes axios#10815.
jasonsaayman
approved these changes
May 6, 2026
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.
What
Restructures
lib/helpers/composeSignals.jsfrom a nested if-block to an early-return pattern, reducing indentation and making the flow clearer.Changes
if (timeout || length)toif (!timeout && !signals.length) return;constfor theAbortController(not reassigned)aborted = falseinstead of relying on implicitundefinedif (!signals) returnat the top ofunsubscribefor cleaner double-call protectionWhy not AbortSignal.any()
I explored using
AbortSignal.any(signals)instead of manualaddEventListenercalls. While it works for basic abort scenarios, it introduces subtle event-loop timing differences that cause the fetch adapter's stream-abort tests to fail (10 of 42 fetch tests hang). The composed signal's abort event fires in a different microtask queue compared to the direct listener approach, which changes the order of operations during stream abort handling. Until that's resolved upstream, the manual approach is more reliable.Tests
All 45 relevant tests pass (3 composeSignals + 42 fetch adapter).
Summary by cubic
Refactors
composeSignalsto use an early-return pattern with small safety guards while keeping manual listener composition to preserve abort timing. No API or behavior changes.Description
if (!timeout && !signals.length) returnconstforAbortControlleraborted = falseunsubscribeto ignore double callsAbortSignal.any()AbortSignal.any()changes event-loop timing and breaks stream-abort tests; manual listeners keep current behaviorlib/helpers/composeSignals.jsis changedv1.xinto this branch; no functional changesDocs
/docs/thatcomposeSignalsuses manual signal composition and an early-return guard for empty inputTesting
composeSignals, 42 fetch adapter)Semantic version impact
Written for commit e7b6bd5. Summary will update on new commits.