New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Axios race condition with cancel token? #4043
Comments
It seems @rohankulshreshtha touches on what I am noticing in this issue here: #2418 (comment)
I'm not quite sure if there is a way to resolve this though? Can I cancel a request without sending it to the server if it happens at the exact same time as it's cancelled? |
Yes, the current Axios cancellation API has race conditions due to the asynchronous nature of CancelToken, since it uses Promises internally, so the internal abort method of the XMLHTTPRequest can be fired not within the same event tick. This is potentially fixed by #3305 which adds the AbortController synchronous interface to the lib as an alternative cancellation API. |
@DigitalBrainJS wow awesome, thanks so much for that info. I felt like I was going crazy. So would a workaround for now (until it's merged into axios), be to use Thanks again! |
@9mm Unfortunately no. |
Describe the issue
I'm using axios in the browser.
Cancel token exceptions do not appear to correspond 100% with what Chrome developer tools considers a response failure.
Essentially I want to retry certain requests (even POST requests) if the server doesn't respond within
5000ms
. Obviously with non-idempotent requests it's important that success/failure of response matches the server.So I tried to implement a connection timeout using the following code. A more simple version of this code is here, and it has the same problem.
I noticed that if I set the connection timeout to be as close as possible to the time it takes for server to respond (to emulate a request finishing right at the time out), there appears to be a race condition where cancel is retried even though it was successful
I have tried
axios-retry
and it has the same issue.Example Code
Code snippet to illustrate your question
Expected behavior, if applicable
I don't know if it's my code, a limitation of JS, or axios, but I would expect that cancel would never get called, as the timeout is cleared in the success callback.
Environment
^0.21.1
XHR
Chrome
latest
N/A
OSX latest
vue 3
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
The text was updated successfully, but these errors were encountered: