fix(xhr): unsubscribe cancelToken and signal on error, timeout, and abort paths#10787
Merged
jasonsaayman merged 3 commits intoaxios:v1.xfrom Apr 25, 2026
Merged
Conversation
jasonsaayman
approved these changes
Apr 25, 2026
ModyQyW
added a commit
to uni-helper/uni-network
that referenced
this pull request
May 7, 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.
The xhr adapter's
onabort,onerror,ontimeout, andonCanceledhandlers reject the promise but never rundone(), so the listener they added tocancelTokenorAbortSignalstays attached. If you reuse one token or controller for many requests, this turns into a memory leak: every failed request retains a listener holding the full config.Quick repro:
The fix just adds a
done()call to each of the four error handlers. The success path and the http/fetch adapters already do this.Summary by cubic
Fixes a memory leak in the
axiosXHR adapter by callingdone()on error, timeout, abort, and cancel paths to unsubscribecancelToken/AbortSignallisteners. Prevents listener buildup when reusing tokens or controllers.Description
done()inonabort,onerror,ontimeout, andonCanceledto remove listeners; aligns with success path andhttp/fetchadapters.Docs
/docs/cancellation guide to note XHR now auto-cleans listeners on error/abort/timeout and that reusing tokens/controllers no longer leaks listeners.Testing
cancelTokenlistener is removed after network error, timeout, and browser abort.AbortSignallistener count returns to zero after a network error.Semantic version impact
Written for commit 8653298. Summary will update on new commits.