3

I was wondering if there is a way with HAProxy to re-send a failed request to another server if the original server is down.

We run a REST API on multiple servers behind multiple HAProxy instances.

There is no balance affinity, balance is done purely on round-robin.

To upgrade one server we can just restart it and due to health checks HAProxy will usually not send any data to this server.

BUT: If the server goes down between two health checks and HAProxy forwards a HTTP request to that server without knowing yet that it's down - that request fails (obviously).

Is there a way to configure HAProxy in such a way that it will notice that the connection went down and retry on another server?

Or at least make HAProxy mark that server as unhealthy directly so we only loose one request and not multiple ones during the transition.

HAProxy is running inside a docker container and the servers are also docker containers.

Tigraine
  • 205
  • 1
  • 8

1 Answers1

3

Yes in version 2.0 haproxy has implemented layer 7 retries.

The new retry-on configuration directive defines in which case to retry failed HTTP request to another server. Earlier versions had option redispatch and retries but would only redispatch in case of connection problems (not eg. errors/timeouts after connection has been established).

Be careful not to retry POST so you don't end up with multiple duplicate database submissions in case of eg. slow backends.

Example:

backend test
    balance roundrobin
    option redispatch 1
    retry-on all-retryable-errors
    retries 3
    http-request disable-l7-retry if METH_POST

    server app1 192.168.0.1:80 maxconn 30 check
    server app2 192.168.0.2:80 maxconn 30 check
    server app3 192.168.0.3:80 maxconn 30 check
seven
  • 231
  • 1
  • 8