title: Browser drops POST when Apache KeepAlive is on
body: <p>For many years I have had apache keep-alive turned on for performance reasons. It allows connections to be reused and makes my pages load subtly faster. However, in the last several months a strange issue has started to happen.</p>
  
  <p>Sometimes, a connection from a user's browser to my application gets dropped which causes data to not get saved and an error to be presented.  I have done a considerable amount of testing and think that I have narrowed the problem down.  It doesn't matter which browser I use. The database and server side scripting are not a factor. It only happens with POSTs not with GETs which is interesting.  It goes away if I disable keep-alive.</p>
  
  <p>Here is what I think is happening.  I have KeepAliveTimeout set to 1 second. After 1 second, the server terminates the connection but it takes a short amount of time (lets say 100ms) for the client to realize it was terminated.  So, between 1 second and 1.1 seconds, if the client attempts to reuse the connection and POST some data, that POST will fail.  I've reproduced this by making a script that POSTs some data exactly at 1 second intervals, and I can see every other connection from the client getting dropped. If I change the script to POST at 0.9 second intervals or 1.1 second intervals it never drops a connection because the specific timing window is avoided.  If I change KeepAliveTimeout to 2 seconds or some other number, then it just pushes out the timing window and doesn't really solve the problem.</p>
  
  <p>My POSTs are coming from javascript (jquery.ajax), but I imagine it could happen from a regular form POST as well if you got the timing right.</p>
  
  <p>In Safari and IE, the connection gets immediately dropped and fails. In Firefox and Chrome the browser stalls for dozens of seconds and then re-sends the request on a new connection which succeeds.</p>
  
  <p>If this is just a fundamental problem with keepalive it is confusing to me why this worked for years and only started doing this in the last few months. Temporarily, I have disabled keep-alive, but I would like to find a way to use it if possible.  And I am hoping that someone here knows of a solution.</p>