HAProxy http-reuse never option not working for HAProxy 1.9.8 and 2.0.1

Hi,

First of all, I would like to clarify some points. Prior the version 1.9, there is no connection pool. Server connections are shared between sessions. It means a session may decide to steal the server connection of another session. But when a session dies, if it still has a server connection, this one is closed. When http-reuse never is set, there is no connection sharing. So the server connection will be private to the session. If a request is routed to another server, the previous connection is closed and a new one is opened. We don’t speak of connection pools here because a server connection cannot be kept alive without a session.

Since the version 1.9, there are connection pools on the servers. So the way http-reuse works is almost the same. Except that when a session dies, the server connection is moved in a pool of idle orphan connections. You can limit the number of idle connections for a server by setting pool-max-conn. Take also a look to pool-purge-delay. In addition, a session may now own a list of server connections, not only one, limited by the frontend parameter max-session-srv-conns (default to 5). These connections are still shared, following http-reuse rules, as before. So if http-reuse never is set, first N server connections will be kept attached to a session. Other will be closed at the end of the HTTP transaction.

So, the documentation must be fixed because some parts are wrong, some others are not really clear. You may be surprised the newer server connection is closed instead of the older one. It may be discussed. Maybe it could be a config option. But that’s said, is there still any issue related to what you observe ?

Ok, my analysis must have been timing depend, I will do some more digging to confirm.

@capflam Thanks a lot for the clarification!

I observed that when http-reuse never is set:
With 3 backend servers,

  1. When setting max-session-srv-conns to 1, connection is getting closed for only one server (third server to which HAProxy establishes connection) after end of its HTTP transaction.
  2. When setting max-session-srv-conns to 0, connection is closed for last 2 servers (to which HAProxy establishes connection) after their HTTP transaction.

With 2 backend servers,

  1. When max-session-srv-conns is set as 1, connections to servers are not closed after HTTP transaction.
  2. When max-session-srv-conns is set as 0, connections to the second server is closed after its HTTP transaction.

Is this the expected behaviour.

A bug was fixed about max-session-srv-conns. See cee03890. So now, the right number of connections will be kept open for a given session.

Otherwise, it is the current behaviour. When max-session-srv-conns idle connections are reached for a session, the new ones are closed. So, with max-session-srv-conns set to 1, only the older one is kept alive. As I said, it is debatable. There are some technical constraints to explain this choice but don’t know which ones.

With http-reuse safe mode, I observed that when max-pool-conn is not set, max-session-srv-conns has no effect (that is, no server connection gets closed after their HTTP transaction even when I set it to 0). When max-pool-conn is set to any value (tried setting it to 0,1,2… ), max-session-srv-conns behaves exactly like it behaves when http-reuse never is set.

So, according to my observation, with http-reuse safe mode, max-session-srv-conns works when max-pool-conn is explicitly set? Please clarify.

First of all, I didn’t check all combinations, but it seems there is a small bug with pool-max-conn. Only N-1 connections are kept alive instead of N. However, I must dig a little to be sure .

BTW, once http-reuse safe is set (or not never in fact), the connection pools will be used. It means a connection may live without any session. So a connection remains attached to a session, If it is not possible because max-session-srv-conns is reached, it is attached to the server with pool-max-conn as limit. When a session dies, server connections are re-attached, if possible, to the corresponding server.

pool-max-conn is by default unlimited (-1). I guess if you set it to 0, it will be the same than http-reuse never.