Search code examples
haproxy

HAProxy : Prevent stickiness to a backup server


I'm facing a configuration issue with HAProxy (1.8).

Context:

  • In a HAProxy config, I have a several severs in a backend, and an additional backup server in case the other servers are down.
  • Once a client gets an answer from a server, it must stick to this server for its next queries.
  • For some good reasons, I can't use a cookie for this concern, and I had to use a stick-table instead.

Problem:

  • When every "normal" server is down, clients are redirected to the backup server, as expected.
  • BUT the stick-table is then filled with an association between the client and the id of the backup server.
  • AND when every "normal" server is back, the clients which are present in the stick table and associated with the id of the backup server will continue to get redirected to the backup server instead of the normal ones!

This is really upsetting me...

So my question is: how to prevent HAProxy to stick clients to a backup server in a backend?

Please find below a configuration sample:

defaults
  option redispatch

frontend fe_test
  bind 127.0.0.1:8081
  stick-table type ip size 1m expire 1h
  acl acl_test  hdr(host) -i whatever.domain.com
  ...
  use_backend be_test if acl_test
  ...

backend be_test
  mode http
  balance roundrobin
  stick on hdr(X-Real-IP) table fe_test
  option httpchk GET /check
  server test-01 server-01.lan:8080 check
  server test-02 server-02.lan:8080 check
  server maintenance 127.0.0.1:8085 backup

(I've already tried to add a lower weight to the backup server, but it didn't solve this issue.)

I read in the documentation that the "stick-on" keyword has some "if/unless" options, and maybe I can use it to write a condition based on the backend server names, but I have no clue about the syntax to use, or even if it is possible.

Any idea is welcome!


Solution

  • So silly of me! I was so obsessed by the stick table configuration that I didn't think to look in the server options...

    There is a simple keyword that perfectly solves my problem: non-stick

    Never add connections allocated to this sever to a stick-table. This may be used in conjunction with backup to ensure that stick-table persistence is disabled for backup servers.

    So the last line of my configuration sample simply becomes:

    server maintenance 127.0.0.1:8085 backup non-stick
    

    ...and everything is now working as I expected.