From 9400a3924d24d4c72cb11ca40efe9b045880ddd7 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 23 Nov 2018 23:10:39 +0100 Subject: [PATCH] MEDIUM: mux-h1: Add keep-alive outgoing connections in connections list 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/mux_h1.c b/src/mux_h1.c index b70afa7ae..4d9db7fba 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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 */