]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux-h1: Add keep-alive outgoing connections in connections list
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 23 Nov 2018 22:10:39 +0000 (23:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 1 Dec 2018 16:37:27 +0000 (17:37 +0100)
With the legacy representation, keep-alive outgoing connections are added in
private/idle/safe connections list when the transaction is cleaned up. But this
stage does not exist with the HTX representaion because a new stream, and
therefore a new transaction, is created for each request. So it is now handled
when the stream is detached from the connection.

src/mux_h1.c

index b70afa7ae6737a297171ef623f98d6cce6039a11..4d9db7fba4d9e70b324121d27ce4197eae3da9a3 100644 (file)
@@ -1633,6 +1633,26 @@ static void h1_detach(struct conn_stream *cs)
        h1c = h1s->h1c;
        h1s->cs = NULL;
 
+       if (conn_is_back(h1c->conn) && (h1s->flags & H1S_F_WANT_KAL)) {
+               /* Never ever allow to reuse a connection from a non-reuse backend */
+               if (h1c->conn && (h1c->px->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR)
+                       h1c->conn->flags |= CO_FL_PRIVATE;
+
+               /* we're in keep-alive with an idle connection, monitor it if not already done */
+               if (h1c->conn && LIST_ISEMPTY(&h1c->conn->list)) {
+                       struct server *srv = objt_server(h1c->conn->target);
+
+                       if (srv) {
+                               if (h1c->conn->flags & CO_FL_PRIVATE)
+                                       LIST_ADD(&srv->priv_conns[tid], &h1c->conn->list);
+                               else if (h1s->flags & H1S_F_NOT_FIRST)
+                                       LIST_ADD(&srv->safe_conns[tid], &h1c->conn->list);
+                               else
+                                       LIST_ADD(&srv->idle_conns[tid], &h1c->conn->list);
+                       }
+               }
+       }
+
        h1s_destroy(h1s);
 
        /* We don't want to close right now unless the connection is in error */