title: HAproxy passive health checking
body: <p>I'm new to haproxy and load balancing. I want to see what happens when a backend host is turned off while the proxy is running.</p>
  
  <p>The problem is, if I turn off one of the backends and refresh the browser the page immediateltly exposes a 503 error to the user. After the next page load, it no longer gets the error since presumably that backend has been removed from the pool.</p>
  
  <p>As a test I have set up two backend Flask apps and configured HAProxy to balance them like so:</p>
  
  <pre><code>backend app
      mode    http
      balanace    roundrobin
      server app1 127.0.0.1:5001 check
      server app2 127.0.0.1:5002 check
  </code></pre>
  
  <p>My understanding according to this:
  <a href="https://www.haproxy.com/doc/aloha/7.0/haproxy/healthchecks.html#check-parameters" rel="nofollow">https://www.haproxy.com/doc/aloha/7.0/haproxy/healthchecks.html#check-parameters</a></p>
  
  <p>is that every 2 seconds a the backend hosts are pingged to see if they are up. Then they are removed from the pool if they are down. The 5xx error happens between the time I kill the backend and the 2 seconds.</p>
  
  <p>I would think there is a way to get around this 5xx error by having HAProxy perform a little logic such that if a request from the frontend fails, it would then remove that failed backend from the pool and then switch to another and make another request. This way the user would never see the failure.</p>
  
  <p>Is there a way to do this, or should I try something else so that my user does not get an error?</p>