title: Haproxy close connections to backup hosts when primary comes back
body: <h2>Question</h2>
  
  <p>Can I get haproxy to close all connections to backup hosts when a primary host becomes available after being down?</p>
  
  <h2>Context</h2>
  
  <p>I am using HAproxy to do failover for pubsub. </p>
  
  <p>The haproxy backend config looks something like this:</p>
  
  <pre><code>listen pubsub 0.0.0.0:1234
      mode tcp
  
      server primary primary.x.com:1234 weight 1 inter 500 rise 10 fall 5 check
      server backup backup.x.com:1234 weight 1 inter 500 rise 10 fall 5 check backup
  </code></pre>
  
  <p>I make long lived connections for both the publish and the subscribe sides.</p>
  
  <p>the problem is in the scenario that:</p>
  
  <ul>
  <li><code>primary</code> goes down</li>
  <li><code>A</code> connects to <code>backup</code> and publishes</li>
  <li><code>B</code> connects to <code>backup</code> and subscribes</li>
  <li><code>primary</code> is fixed and becomes alive again</li>
  <li><code>C</code> connects to <code>primary</code> and publishes <strong>but <code>B</code> does not receive it</strong></li>
  <li><code>D</code> connects to <code>primary</code> and subscribes <strong>but does not get <code>A</code>'s messages</strong></li>
  </ul>
  
  <p>The best solution to this problem that I can see is to have haproxy forcibly close all connections to backup hosts when a primary becomes available again.</p>