-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Node retries not compatible with timeouts #1487
Node retries not compatible with timeouts #1487
Comments
I've investigated a bit further and it turns out that the timeout functionality is not compatible with using the promise version of superagent i.e. using |
I found the same problem in version 5.0.5. Using |
The issue here is that when a timeout occurs, superagent calls |
To reproduce: const request = require('superagent');
const main = async () => {
const req = request('http://localhost:8000');
req.timeout(1000);
await req.catch(err => {
if (err.timeout) {
console.log('got timeout');
}
throw err;
});
};
main().then(console.log, console.log); and in another terminal, run a server that will not reply. Netcat will do: nc -klp 8000 |
v5.3.0 published to npm and GitHub releases page with changelog |
I'm looking at integrating superagent to make a server side call to a flaky backend API. The API either responds quickly or doesn't respond at all and needs to therefore be retried.
I'm therefore using
retry(3)
in combination withtimeout({ deadline: 3000 })
. However the timeout is overruling the retry and throwing anAborted
error which returns a 500 error to the client. From what I can tell the following is happening when the request takes too long:GET
request times out so emits anabort
abort
handler thenreject
s the requestAborted
error then causes 500 error to clientLooking at the code the retry logic attempts to reset the
_aborted
andtimedout
properties, but it looks like by then it is too late asreject
is called.Is there a way I can therefore retry when the API call times out?
The text was updated successfully, but these errors were encountered: