question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node retries not compatible with timeouts

See original GitHub issue

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 with timeout({ deadline: 3000 }). However the timeout is overruling the retry and throwing an Aborted error which returns a 500 error to the client. From what I can tell the following is happening when the request takes too long:

  1. Superagent makes a get request to backend API
  2. GET request times out so emits an abort
  3. abort handler then rejects the request
  4. Retry logic kicks in and decides that we should retry
  5. Aborted error then causes 500 error to client
  6. Backend API is then retried
  7. If API call fails then is retried twice more otherwise finishes

Looking at the code the retry logic attempts to reset the _aborted and timedout properties, but it looks like by then it is too late as reject is called.

Is there a way I can therefore retry when the API call times out?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
djmitchecommented, Nov 25, 2019

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
0reactions
niftylettucecommented, Jun 28, 2020

v5.3.0 published to npm and GitHub releases page with changelog

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node retries not compatible with timeouts · Issue #1487
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...
Read more >
node.js - Nodejs http retry on timeout or error
I was looking for same thing and found interesting module requestretry, well suited for such requirement. Here is usage:
Read more >
Error handling in Step Functions
This example of a Retry field retries any error except States.Timeout . "Retry": [ { "ErrorEquals": [ "States.Timeout" ], "MaxAttempts" ...
Read more >
Cluster Timeouts | ScyllaDB Docs
Cluster Timeouts¶. Issue: cluster is experiencing timeouts due to server overload. Possible Root Cause: aggressive retry policy ...
Read more >
How to fix DynamoDB timeouts in Serverless apps
In this post we are going to look at how to debug DynamoDB timeouts in Serverless apps. This is a fairly specific issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found