]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: htx: Try to take a connection over if it has no owner.
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 13 Dec 2018 17:46:22 +0000 (18:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Dec 2018 17:54:27 +0000 (18:54 +0100)
In the mux detach function, when using HTX, take the connection over if
it no longer has an owner (ie because the session that was the owner left).
It is done for legacy code in proto_http.c, but not for HTX.
Also when using HTX, in H2, try to add the connection back to idle_conns if
it was not already (ie we used to use all the available streams, and we're
freeing one). That too was done in proto_http.c.

src/mux_h1.c
src/mux_h2.c

index 21f539d1fed3e444b31be079354889087b849222..bd7d0383533c0f200137caa97599fa73a4f359c8 100644 (file)
@@ -22,6 +22,7 @@
 #include <proto/connection.h>
 #include <proto/http_htx.h>
 #include <proto/log.h>
+#include <proto/session.h>
 #include <proto/stream.h>
 #include <proto/stream_interface.h>
 
@@ -1925,13 +1926,21 @@ 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) && h1c->conn->owner) {
+       if (conn_is_back(h1c->conn) && (h1s->flags & H1S_F_WANT_KAL) &&
+           !(h1c->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) {
+               struct stream_interface *si = cs->data;
+               struct stream *s = si_strm(si);
+
                /* 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)
+               if ((h1c->px->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR)
                        h1c->conn->flags |= CO_FL_PRIVATE;
 
+               if (!(h1c->conn->owner)) {
+                       h1c->conn->owner = s->sess;
+                       session_add_conn(s->sess, h1c->conn, s->target);
+               }
                /* we're in keep-alive with an idle connection, monitor it if not already done */
-               if (h1c->conn && LIST_ISEMPTY(&h1c->conn->list)) {
+               if (LIST_ISEMPTY(&h1c->conn->list)) {
                        struct server *srv = objt_server(h1c->conn->target);
 
                        if (srv) {
index 806c817bd3ed6f7d93fd443266b055ff40175b7e..807f3197dda5005bc06a565e12e0884af8a8d3cc 100644 (file)
@@ -22,7 +22,9 @@
 #include <common/net_helper.h>
 #include <proto/connection.h>
 #include <proto/http_htx.h>
+#include <proto/session.h>
 #include <proto/stream.h>
+#include <proto/stream_interface.h>
 #include <types/session.h>
 #include <eb32tree.h>
 
@@ -2815,6 +2817,34 @@ static void h2_detach(struct conn_stream *cs)
                return;
 
        h2c = h2s->h2c;
+       if (h2c->proxy->options2 & PR_O2_USE_HTX) {
+               struct stream_interface *si;
+               struct stream *s;
+
+               si = cs->data;
+               s = si_strm(si);
+               if (!(h2c->conn->flags &
+                   (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) {
+                       if (!h2c->conn->owner) {
+                               h2c->conn->owner = s->sess;
+                               session_add_conn(s->sess, h2c->conn, s->target);
+                       }
+                       /* Never ever allow to reuse a connection from a non-reuse backend */
+                       if ((h2c->proxy->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR)
+                               h2c->conn->flags |= CO_FL_PRIVATE;
+                       if (LIST_ISEMPTY(&h2c->conn->list)) {
+                               struct server *srv = objt_server(h2c->conn->target);
+
+                               if (srv) {
+                                       if (h2c->conn->flags & CO_FL_PRIVATE)
+                                               LIST_ADD(&srv->priv_conns[tid], &h2c->conn->list);
+                                       else
+                                               LIST_ADD(&srv->idle_conns[tid], &h2c->conn->list);
+                               }
+
+                       }
+               }
+       }
        h2s->cs = NULL;
        h2c->nb_cs--;
        if (h2c->flags & H2_CF_DEM_TOOMANY &&