What Is The Default XHR Timeout?

4,082 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,
Reply all
Reply to author
Forward
0 new messages