What Is The Default XHR Timeout?

4,199 views
Skip to first unread message

Bart Wood

unread,
Sep 15, 2015, 4:45:27 PM9/15/15
to Chromium-discuss
Sorry for what is probably a well known question / answer but I haven't been able to figure this out over the past hour.

How long will XMLHttpRequests wait in Chrome before timing out?

From the XMLHttpRequest docs it appears like there is a timeout default value of "0" which means to wait forever.  

But when I run tests in Chrome it looks like the timeout is 2 minutes.

I created a very simple ExpressJS server that looks like this:
 
var express = require('express');
var app = express();

app.get('/theWaitTest', function (req, res) {
  var waitTime = 121 * 1000;
  console.log('waiting ' + waitTime + ' MS');
  setTimeout(function(){
console.log('done waiting');
res.send('Hello World');
  }, waitTime);
});

app.get('/', function (req, res) {  
  res.send('Hello World');
});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

I hit my site at localhost:3000 in Chrome and I run this code in my console:
  var request = new XMLHttpRequest();
  request.ontimeout = function () { console.log('the request timed out.'); };
  request.open('GET', 'theWaitTest', true);
  request.send();

If my server is set to delay for 119 seconds the XHR request succeeds in Chrome with no timeout.  If my server is set to delay at 121 seconds Chrome times out the XHR request with this error "net::ERR_EMPTY_RESPONSE".

So, is 120 seconds the default amount of time that Chrome waits on XHR requests?

Thanks,

Jonathan Rosa

unread,
Mar 22, 2026, 8:09:02 AM (2 days ago) Mar 22
to Chromium-discuss, Bart Wood
Hi, Bart, I will answer your question 11 years late to give you closure.

The default timeout for XHR on Chrome is none.

That 2 min timeout you saw was Node.js (which Express.js sits on top of) closing your idle connection because the connection was idle. `server.setTimeout(ms) ` overrides this.

The real limit for idle connection depends on the kernel. On Windows and Linux, connections can be idle for 2 hours before the kernel closes it.

Happy coding :)
Reply all
Reply to author
Forward
0 new messages