Reputation: 930
Can I get haproxy to close all connections to backup hosts when a primary host becomes available after being down?
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 downA
connects to backup
and publishesB
connects to backup
and subscribesprimary
is fixed and becomes alive againC
connects to primary
and publishes but B
does not receive itD
connects to primary
and subscribes but does not get A
's messagesThe 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.
Upvotes: 7
Views: 4591
Reputation: 83
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
Upvotes: 7