Prevent HAProxy from toggling back from fallback to master

Solution 1:

There is a workaround to do what you need. Simply put a very high value on the rise parameter, and an inter of a few seconds, like the example below:

listen  sql-cluster 0.0.0.0:1433
        balance roundrobin
        server  sql01 192.168.100.109:1433 check backup
        server  sql02 192.168.100.180:1433 check inter 5s fall 3 rise 99999999

In this example, sql01 is backup, and sql02 is active. If master is down, sql01 is up. For sql02 to return to active, it must do 99.999.999 healthy checks, with interval of 5 seconds... this is around 15 years!

Solution 2:

Use the stick 🏑 option. From the official HAproxy blog:

Automatic failover without failback

The configuration below makes HAProxy to use s1 when available, otherwise fail over to s2 if available. When a failover has occurred, no failback will be processed automatically, thanks to the stick table:

backend bk_app
 stick-table type ip size 1 nopurge peers LB
 stick on dst
 server s1 10.0.0.1:80 check
 server s2 10.0.0.2:80 check backup