1

I'm using express.js to generates some route for a private project. This particular route take a very long time to execute (about 3minutes). Since this is a project only for myself, I really don't mind waiting.

Here is my route:

router.get('/', (req, res) => {
  req.setTimeout(0);
  console.log('Start ' + new Date());
  let data = [];
  //... very large code that fetch a lots of data and update the data variable
  res.json(data);
  console.log('End ' + new Date());
});

If I'm executing the request directly in the browser url, the page take a long time to load, but after a while, will display the result correctly.

But if I'm using axios to make an ajax request like so

axios({
  method: 'get', 
  url: `/api/simulation?idSession=${this.props.match.params.session}`,
  timeout: 600000,
}).then(result => {

  this.setState({
    simulation: {
      loading: false,
      data: result.data
    }
  }).catch(err => alert(err));
});

I will receive the first console.log with the word 'Start' and the date, and pretty much exactly 2minutes after that (more or less some milliseconds), I will again receive the 'Start' console.log, and again.

I will receive the 'Start' console log in a loop until I restart the node server or close the browser's page with the ajax request.

I will still see the 'End' console.log after that, but axios seem to ignore it.

I though that by adding the req.setTimeout(0); in my route, it could solve the problem, but it doesn't seem to change anything.

And since the problem only occurs when I call the route via an ajax request with axios, I tried to put a large timeout, but that also did nothing.

Just in case, my nodejs version is 8.11.2, express version is 4.16.3 and axios is 0.18.0

Anyone has an other idea, or a way to disable all timeout?

Thanks

Etienne
  • 177
  • 4
  • 17
  • For anyone stumbling across this try: https://github.com/expressjs/express/issues/3330#issuecomment-390187328 and/or https://stackoverflow.com/q/38882237/1504487 – bennos Jul 28 '20 at 08:29

0 Answers0