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 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.
Keep-alive and server maxconnIt can be used to protect servers against traffic spikes by routing requests to other servers or by queueing requests within HAProxy. The server's maxconn parameter was created at a time when HAProxy did not support keep-alive nor manage a connection pool (back in 2006, around HAProxy 1.2.
The maxcon attributes represent a load factor multiplier that is used to compute the maximum number of connections that HAProxy allows for backends.
Here, HAProxy will accept up to 60,000 TCP connections concurrently. Having this limit prevents denial-of-service scenarios that could happen if HAProxy had to maintain more connections than the server's memory resources allowed.
An HAProxy load balancer lets you specify different load balancing modes, depending on the type of application you're serving. Its round-robin mode will send requests to your servers in a rotation and works well when requests take a small and predictable amount of time to handle, such as HTTP requests.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With