Automattically getting out of backup server

Hi,

I have this setup:

backend hub_server
    mode tcp
    # maximum SSL session ID length is 32 bytes.
    stick-table type binary len 32 size 30k expire 30m
    option tcplog
    option log-health-checks
    acl clienthello req_ssl_hello_type 1
    acl serverhello rep_ssl_hello_type 2

    # use tcp content accepts to detects ssl client and server hello.
    tcp-request inspect-delay 5s
    tcp-request content accept if clienthello

    # no timeout on response inspect delay by default.
    tcp-response content accept if serverhello
    stick on payload_lv(43,1) if clienthello

    # Learn on response if server hello.
    stick store-response payload_lv(43,1) if serverhello
    option ssl-hello-chk

    tcp-request inspect-delay 5s
    tcp-request content accept if { req.ssl_hello_type 1 }

    server server1 hub.lxd:443 weight 11 check non-stick inter 1s fall 3 rise 2
    server server2 10.97.89.14:443 weight 22 check non-stick inter 1s fall 3 rise 2
    server server3 127.0.0.1:4503 send-proxy-v2 backup non-stick

The local backup is a PHP page replying with a 503 Service Unavailable and Retry-After: 30 headers, this is a basic page I use elsewhere to put web services under maintenance. It also runs a JavaScript to force refresh when back available:

    var maintenance_check = function() {
        var request = new XMLHttpRequest();
        request.open( 'HEAD', window.location, true );

        request.onload = function() {
            if ( this.status >= 200 && this.status < 400 ) {
                // Maintenance mode ended. Reload page.
                window.location.reload();
            } else {
                // Still in maintenance mode. Try again in 3 seconds.
                setTimeout( maintenance_check, 3000 );
            }
        };

        request.onerror = function() {
            // Connection error. Try again in 3 seconds.
            setTimeout( maintenance_check, 3000 );
        };

        request.send();
    };
    maintenance_check();

So, I shutdown server1 and server2, visit the site and get the 503 temporary page, I can see the JavaScript requesting in the console and getting 503 replies. All good. I leave that page opened, and start server1. In another browser (and in the logs) I can see that Haproxy reacted and shows the web app.

But in the first browser, the requests made every 3 seconds still get the 503 page. If I hit F5, I am still seeing the 503. I need to hit Ctrl + F5 to get the running webapp.

Any clue on how to solve that ?

Add this do your non-backup servers:

on-marked-up shutdown-backup-sessions

See:

https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#5.2-on-marked-up

Thank you !