title: Inconsistent browser retry behaviour for timed out POST requests
body: <p>I am experiencing occasional retries for a POST request, when there is no response from server due to timeout. All modern browsers have retry logic for idempotent requests (GET, HEAD, etc) but I am unable to reason out why it happens for a POST request.</p>
  <p>I am testing this case using a simple node.js server with 3 routes and chrome browser .</p>
  <pre><code>/       : gives a html page with jquery and code snippets to fire ajax requests
  /hi     : gives a text response 'hello'
  /sleep  : request will timeout without any response 
  </code></pre>
  <p>By default, node.js http server times out a request after 2 minutes.</p>
  <h2>retry.js</h2>
  <pre><code>var http = require('http');
  var server = http.createServer();
  
  server.on('request', function(req, res) {
      console.log(new Date() + ' ' + req.method + ' request on ' + req.url);
  
      if (req.url === '/sleep') {
          console.log('!!! sleeping');
      } else if (req.url === '/') {
          html = &quot;$.post('/hi', {'for':'server'}, function() { console.log(arguments) } ).error(function() { console.log(arguments) })&quot;;
          html += &quot;&lt;br&gt;&lt;br&gt;&quot;;
          html += &quot;$.post('/sleep', {'for':'infinite'}, function() { console.log(arguments) } ).error(function() { console.log(arguments) })&quot;;
          html += '&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;&gt;&lt;/script&gt;';
      
          res.writeHead(200, {'Content-Type': 'text/html'});
          res.end(html);
      } else {
          res.writeHead(200, {'Content-Type': 'text/plain'});
          res.end('hello');
      }
  });
  
  server.listen(2020);
  console.log('server listening on port 2020');
  </code></pre>
  <h2>run it</h2>
  <pre><code>$ node retry.js 
  server listening on port 2020
  </code></pre>
  <h2>1</h2>
  <pre><code>Load this page in browser http://localhost:2020
  
  Fri Mar 01 2013 12:21:59 GMT+0530 (IST) GET request on /
  Fri Mar 01 2013 12:21:59 GMT+0530 (IST) GET request on /favicon.ico
  </code></pre>
  <h2>2</h2>
  <p>From Dev console, fire an ajax POST request to /hi using jquery</p>
  <pre><code>$.post('/hi', {'for':'server'}, function() { console.log(arguments) } ).error(function() { console.log(arguments) })
  </code></pre>
  <blockquote>
  <p>Fri Mar 01 2013 12:22:05 GMT+0530 (IST) POST request on /hi</p>
  </blockquote>
  <h2>3</h2>
  <p>Fire a POST request to /sleep, results in a retry after 2 mins and errors out after 4 mins.</p>
  <pre><code>$.post('/sleep', {'for':'infinite'}, function() { console.log(arguments) } ).error(function() { console.log(arguments) })
  </code></pre>
  <p>server logs shows 2 requests</p>
  <pre><code>Fri Mar 01 2013 12:22:21 GMT+0530 (IST) POST request on /sleep
  !!! sleeping
  Fri Mar 01 2013 12:24:21 GMT+0530 (IST) POST request on /sleep
  !!! sleeping
  </code></pre>
  <p>Firing it again, errors out in 2 mins without any retry.</p>
  <pre><code>Fri Mar 01 2013 12:30:01 GMT+0530 (IST) POST request on /sleep
  !!! sleeping ?
  </code></pre>
  <h3>It's not getting retried until we fire a request to /hi (or any other url) that results in a response. And retry happens for just one subsequent request to /sleep.</h3>
  <h2>In browser, the network tab shows the pattern like</h2>
  <pre><code>/hi - success 
  /sleep - cancelled - 4 mins (retry happens)
  /sleep - cancelled - 2 mins (no retry)
  /sleep - cancelled - 2 mins (no retry)
  /hi - success 
  /sleep - cancelled - 4 mins (retry happens)
  /sleep - cancelled - 2 mins (no retry)
  /sleep - cancelled - 2 mins (no retry)
  </code></pre>
  <hr />
  <h2>Question</h2>
  <p>Though we need to design our web app to tolerate these extra requests (either by browsers or any other intermediaries), this inconsistent browser retries looks weird. I had observed this behaviour in chrome (v16 &amp; v24) &amp; firefox.</p>
  <p>Can someone help me to understand the browser retry logic behind timed out non-idempotent requests ?</p>
  <h3>Other relevant stackoverflow questions</h3>
  <p><a href="https://stackoverflow.com/questions/14302512/what-happens-when-no-response-is-received-for-a-request-im-seeing-retries">What happens when no response is received for a request? I&#39;m seeing retries</a></p>