HAProxy Session Persistence v.s. Drain State

Hello HAProxy community!

I am seeking clarification on documentation concerning session persistence and the drain state.

In a few words,

can I leverage cookie/ip “session persistence” (linked above) to route “new” requests to a server in drain state?

In more words,

Consider I have two backend servers (backend_a and backend_b) load balanced by an HAProxy instance. Now let my client perform the following three requests:

  1. Initial sign in/authentication (in the background, we were load-balanced onto backend_a)
  2. Load resource (table_t) onto the current server servicing us (in this case backend_a). This resource comes from another downstream component irrelevant to this question.
  3. Stream the contents of table_t from the same server we loaded the table onto (backend_a) to somewhere on our client.

For obvious reasons, these three requests need to occur in order on the same backend server (backend_a). For simplicity’s sake, let me say that we load balance based on a hash of the username. Our backend config then looks like

backend server
  balance hdr(username-hash)
  hash-type consistent
  ... 
  option redispatch

If I decide to drain backend_a using the runtime API after request 2 is sent AND BEFORE REQUEST 3 IS SENT, is there any way to get request 3 onto backend_a? From what I have found (Management | Enable/Disable Servers | HAProxy Enterprise 2.5r1), the drain state will

set server state to DRAIN (remove from load-balancing, but remain available for health checks and persistent connections)

But, I’m not sure if cookie/IP persistence constitutes a “persistent connection”.

TL;DR will cookie or ip based “persistence” allow new requests (without an existing TCP connection) to connect to a server in the drain state while using option redispatch?

Hi,
I think you want to read this blog article, it’s old, but its content is still pretty accurate:

Using a “deterministic” LB algorithm (like the hash you mentionned) does not work with “drain” mode. That said, if you enable cookie or stick table based persistence, then the following happens:

  • if a new user comes in, he will be routed to any server in the backend but the ones in DRAIN mode
  • if a user comes with a persistence information pointing to a server in DRAIN mode, then HAProxy will route this user to the server (unless the server is set as DOWN by the health check of course)

It’s not a “persistent TCP connection”, it’s more a HTTP based session persistence, so all the traffic from a single user will be routed to a server in drain mode.

Note that the log line from HAProxy will have some very useful persistence flags too.

1 Like

Thank you so much @Baptiste ! This looks like exactly what I need :slight_smile: