7

Question

Can I get haproxy to close all connections to backup hosts when a primary host becomes available after being down?

Context

I am using HAproxy to do failover for pubsub.

The haproxy backend config looks something like this:

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

I make long lived connections for both the publish and the subscribe sides.

the problem is in the scenario that:

  • primary goes down
  • A connects to backup and publishes
  • B connects to backup and subscribes
  • primary is fixed and becomes alive again
  • C connects to primary and publishes but B does not receive it
  • D connects to primary and subscribes but does not get A's messages

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.

Nick
  • 900
  • 1
  • 10
  • 19

1 Answers1

7

I know this is an older question, and you've probably found a solution by now, but if you haven't then I think the answer you are looking for is the on-marked-up server option. This is a new server option as of version 1.5.

According to the documentation, you can provide an action to perform when a server is marked as "up". Currently, the only action is:

shutdown-backup-sessions: Shutdown sessions on all backup servers...

server primary ... on-marked-up shutdown-backup-sessions