axios: Error: timeout of 0ms exceeded
Sentry reported a random error coming from Axios, Error: timeout of 0ms exceeded
.
Under what circumstances would this error appear? We don’t have timeout settings configured, and 0ms seems like a mighty short time for any request to finish, so why is this error thrown?
It appears to have been a one off that is not readily reproducible, so I can’t provide test code, but the underlying network error seems to have been ECONNABORTED
.
Axios version 0.18.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 87
- Comments: 37 (1 by maintainers)
For everyone enjoying this bug, I managed to catch this locally and match it up with a Sentry error report. It appears that this is the result of a genuine timeout, but the reporting of ‘0ms’ is simply a bug in axios’s reporting. So the errors are valid, however they are (or were in my case) real timeouts of significantly longer duration. @adamreisnz please could you re-tag this issue as a bug, which might get it some visibility.
We are seeing this when a stalled connection times out after 30 seconds. I think maybe the errors are valid, but the length of timeout is being misreported as 0.
I am seeing this on an app hooked up with sentry and axios as well. For me this is only happening for users on macOS who are running the Safari browser.
Safari versions that have thrown the error: 12.1, 12.0.3, 12.0.2, 12.0, and 11.1.2
For my users they were all making a GET request. Same error message too ‘timeout of 0ms exceeded’.
From the breadcrumbs it appears that they all ran into this problem right as they were loading the app, as if they had a connectivity issue. The error code for the request seems to be ‘ECONNABORTED’. I wouldn’t expect Axios to be throwing an additional error here on top of the failed request.
@jasonsaayman why is this flagged as a question? I still think Axios should handle this properly somehow, a timeout of 0ms doesn’t seem to make sense.
In our case it was/is a combination of slow api calls and users losing connection, whether it be because they went from wifi to 4g or because they lost internet alltogether.
@NatPDeveloper I don’t know if these two are related :
Error: Network Error
&Error: timeout of 0ms exceeded
But you will find some hints about
Error: Network Error
here #383We are also experience this problem, and we can not reproduce it. It is only visible in sentry logs. I’m doubt that it is bug in axios. It is clear though, that error is thrown here https://github.com/axios/axios/blob/6fe506fda290ba935c2641f68f1fcba7f4a16cd3/lib/adapters/xhr.js#L91 and
0ms
is displayed correctly, because it is 0 by default https://github.com/axios/axios/blob/1b07fb9365d38a1a8ce7427130bf9db8101daf09/lib/defaults.js#L71I tried to find something similar on StackOverflow and on github and here is what I found:
Trying to reproduce this issue I did multiple requests to the same endpoint, enabled ad blockers, did requests after connection close, turned off/on the internet, enabled throttling. Still no luck - I can not reproduce. Maybe the links I posted are somehow related to the problem.
One more detail: from logs I see that multiple api calls failed with “0ms timeout” simultaneously, even calls to different domains.
@Undistraction you’ve mentioned it is a genuine timeout. Did you mean http status 408, 504 or some other timeout?
The Network Error is usually thrown when a browser can’t connect to the internet or to the host. We don’t report those in Sentry, but did get the 0ms exceeded errors in Sentry.
Same here, it’s happening for some of our iOS users reported by sentry, but I can’t reproduce it myself.
sentry.javascript.browser 5.5.0
iOS 11.2.5
Safari 11.0
Getting same error in sentry after a post request.
Also just getting:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout
So basically the issue is that some browsers will trigger the
ontimeout
callback when the connection is aborted, instead of triggering theonerror
callback and it might not be the expected behaviorSo I guess checking if the timeout was set as 0 in this callback to trigger a different error (the usual
Network Error
) for those might be a good idea, because if the timeout was 0, it is expected that this callback should not fire@jasonsaayman @adamreisnz Agree, at least axios should change error message to something like “timeout exceeded” or “request timed out”
@malykhinvi I believe this is an error caused by bad network connection and timed out by browser’s inner timeout.
Axios here prints the wrong error message