]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: servers: Used a locked list for idle_orphan_conns.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 22 Jan 2019 15:11:03 +0000 (16:11 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 26 Feb 2019 17:17:32 +0000 (18:17 +0100)
Use the locked macros when manipulating idle_orphan_conns, so that other
threads can remove elements from it.
It will be useful later to avoid having a task per server and per thread to
cleanup the orphan list.

include/proto/connection.h
include/proto/server.h
src/backend.c

index 45b8a8a5379b3cc76bd1f5270b4ee64c8759e97c..3bfad58ef298102acfa991861d4e0a29517cfeac 100644 (file)
@@ -698,7 +698,7 @@ static inline void conn_free(struct connection *conn)
        }
 
        conn_force_unsubscribe(conn);
-       LIST_DEL(&conn->list);
+       LIST_DEL_LOCKED(&conn->list);
        LIST_INIT(&conn->list);
        pool_free(pool_head_connection, conn);
 }
index 9467f697a92a80bc72daf358621873fa6216e2d0..82c9cbf4f635b6a1c07a0ab92ebe2c645aa657ff 100644 (file)
@@ -252,7 +252,7 @@ static inline int srv_add_to_idle_list(struct server *srv, struct connection *co
                        return 0;
                }
                LIST_DEL(&conn->list);
-               LIST_ADDQ(&srv->idle_orphan_conns[tid], &conn->list);
+               LIST_ADDQ_LOCKED(&srv->idle_orphan_conns[tid], &conn->list);
                srv->curr_idle_thr[tid]++;
 
                conn->idle_time = now_ms;
index d15020aa6141dd1a65e34a87da3123547b75d072..489927e923576b62b7b6657e092c328d365dd157 100644 (file)
@@ -1307,9 +1307,12 @@ int connect_server(struct stream *s)
                    (((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS) ||
                    (((s->be->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) &&
                     s->txn && (s->txn->flags & TX_NOT_FIRST)))) {
-                       srv_conn = LIST_ELEM(srv->idle_orphan_conns[tid].n,
+                       srv_conn = LIST_POP_LOCKED(&srv->idle_orphan_conns[tid],
                            struct connection *, list);
-                       reuse_orphan = 1;
+                       if (srv_conn) {
+                               LIST_INIT(&srv_conn->list);
+                               reuse_orphan = 1;
+                       }
                }
 
                /* If we've picked a connection from the pool, we now have to
@@ -1341,7 +1344,6 @@ int connect_server(struct stream *s)
         * list and add it back to the idle list.
         */
        if (reuse && reuse_orphan) {
-               LIST_DEL(&srv_conn->list);
                srv_conn->idle_time = 0;
                HA_ATOMIC_SUB(&srv->curr_idle_conns, 1);
                srv->curr_idle_thr[tid]--;