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.

Axios not respecting the value I set for "timeout"

See original GitHub issue

Summary

Hi there,

I’ve been using axios a lot in my web application. Everything has been working just fine in most cases. Today, I’ve got a new demand in my application using axios, but I can’t get it working.

I am creating the possibility to import data to my application. The user uploads a .csv file to my server, and with axios I am calling a method in my controller to process data.

The issue I am facing is related to the timeout parameter set when using axios.

I have a large amount of data to import, so it will take more than 2 minutes to process all the data. Whatever value bigger than 2 minutes won’t be considered by axios. It only waits for 2 minutes, and them returns an error.

Am I missing something here? I checked the documentation and made sure I was using what is recommended in “Config order of precedence”, but I still can’t make it work.

Would someone help me out?

Context

  • axios version: e.g.: v0.17.1
  • Environment: e.g.: node v6.9.4, chrome 54, windows 7, react JS, C#, .net Core

My implementation

axios({
  method: 'post',
  url: '/user',
  timeout: 180000, // Let's say you want to wait at least 180 seconds
  data: {
    id: '1234',
  }
})
.then(function (response) {
      console.log(response);
})
.catch(function (error) {
    console.log(error);
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

16reactions
coolgodcommented, Apr 26, 2018

timeout depends on both client side and server side, do you want to check your server side config first? e.g., tomcat timeout configs? or sth like that?

in short, while client is still waiting, the server shouldn’t close that connection.

you could verify this by running a dummy nodejs server which wait, the timeout actually works: server.js

const http = require('http');

const server = http.createServer(function(req, res) {
    console.log('req incoming');
    setTimeout(function() {
        res.write('Hello World!');
        res.end();
    }, 60 * 3 * 1000); // after 3 min
})
.listen(9000);
console.log(server.timeout); // default is 1200000

server.timeout = 60 * 4 * 1000; // 4 min

client.js

const axios = require('axios');

console.log(new Date().toUTCString());
axios({
    method: 'post',
    url: 'http://127.0.0.1:9000',
    timeout: 60 * 4 * 1000, // Let's say you want to wait at least 4 mins
    data: {
      id: '1234',
    }
  })
  .then(function (response) {
        console.log(new Date().toUTCString());
        console.log(response.data);
  })
  .catch(function (error) {
        console.log(error);
  });
7reactions
ziszocommented, Dec 6, 2018

Adding timeout in the config won’t work. Use the following instead: axios.defaults.timeout = 180000;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout feature in the axios library is not working
Let say you've requested the URL through axios and server is taking long time to respond, in this case the axios timeout will...
Read more >
Handling timeout in Axios. Quick and easy - Medium
The default timeout is set to 0 which indicates no timeout. With that default value, any remote end can keep us waiting for...
Read more >
Using Axios timeout to make your application more efficient
Setting Axios timeout properly makes your application perform efficiently even when the called API/URL is not responding in a timely manner.
Read more >
axios - npm
Start using axios in your project by running `npm i axios`. ... When no `transformRequest` is set, must be of one of the...
Read more >
The Power of Axios - Bits and Pieces
If a timeout is not set for an HTTP request, any remote end can keep the request waiting for a longer period. With...
Read more >

github_iconTop Related Medium Post

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