]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: connection: do not use conn->owner when the session is known
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2020 16:08:15 +0000 (17:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 21 Nov 2020 14:29:22 +0000 (15:29 +0100)
At a few places we used to rely on conn->owner to retrieve the session
while the session is already known. This is not correct because at some
of these points the reason the connection's owner was still the session
(instead of NULL) is a mistake. At one place a comparison is even made
between the session and conn->owner assuming it's valid without checking
if it's NULL. Let's clean this up to use the session all the time.

Note that this will be needed for a forthcoming fix and will have to be
backported.

include/haproxy/session.h
src/backend.c
src/connection.c

index 6a24d8a5945300f82061ffd2bccff04a05d69b91..8174a2ae79c8a453f0f198316c8b2bc16dd07f33 100644 (file)
@@ -103,7 +103,7 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
        int found = 0;
 
        /* Already attach to the session or not the connection owner */
-       if (!LIST_ISEMPTY(&conn->session_list) || conn->owner != sess)
+       if (!LIST_ISEMPTY(&conn->session_list) || (conn->owner && conn->owner != sess))
                return 1;
 
        list_for_each_entry(srv_list, &sess->srv_list, srv_list) {
index e0f7dd627b8f0b6a65a8d2fff76535ec3cb9ea81..a76f08ce2d68db1d4567622d39664120f1c76f76 100644 (file)
@@ -1207,7 +1207,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv,
                        /* attach the connection to the session private list
                         */
                        conn->owner = s->sess;
-                       session_add_conn(conn->owner, conn, conn->target);
+                       session_add_conn(s->sess, conn, conn->target);
                }
                else {
                        LIST_ADDQ(&srv->available_conns[tid], mt_list_to_list(&conn->list));
@@ -1563,7 +1563,7 @@ int connect_server(struct stream *s)
                         ((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_SAFE &&
                          srv_conn->mux->flags & MX_FL_HOL_RISK)) {
                        /* If it fail now, the same will be done in mux->detach() callback */
-                       session_add_conn(srv_conn->owner, srv_conn, srv_conn->target);
+                       session_add_conn(s->sess, srv_conn, srv_conn->target);
                }
        }
 
index dc54b9d63e371e475fff79f6f663ec6eb8bd36d6..366bb25b56e7ff2417fa0f82dc0397aeec17597a 100644 (file)
@@ -54,10 +54,10 @@ int conn_create_mux(struct connection *conn)
                        goto fail;
 
                if (sess && obj_type(sess->origin) == OBJ_TYPE_CHECK) {
-                       if (conn_install_mux_chk(conn, conn->ctx, conn->owner) < 0)
+                       if (conn_install_mux_chk(conn, conn->ctx, sess) < 0)
                                goto fail;
                }
-               else if (conn_install_mux_be(conn, conn->ctx, conn->owner) < 0)
+               else if (conn_install_mux_be(conn, conn->ctx, sess) < 0)
                        goto fail;
                srv = objt_server(conn->target);
 
@@ -72,7 +72,7 @@ int conn_create_mux(struct connection *conn)
                        LIST_ADDQ(&srv->available_conns[tid], mt_list_to_list(&conn->list));
                else if (conn->flags & CO_FL_PRIVATE) {
                        /* If it fail now, the same will be done in mux->detach() callback */
-                       session_add_conn(conn->owner, conn, conn->target);
+                       session_add_conn(sess, conn, conn->target);
                }
                return 0;
 fail: