]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: connections: Don't increase curr_used_conns for shared connections.
authorOlivier Houchard <cognet@ci0.org>
Sun, 28 Jun 2020 14:14:09 +0000 (16:14 +0200)
committerOlivier Houchard <cognet@ci0.org>
Sun, 28 Jun 2020 14:16:13 +0000 (16:16 +0200)
In connect_server(), we want to increase curr_used_conns only if the
connection is new, or if it comes from an idle_pool, otherwise it means
the connection is already used by at least one another stream, and it is
already accounted for.

src/backend.c

index 952e37197d5e05e6dd3679e629d345bd6db0835f..51d954babf46bd49a57e3d95a85e7228e15ca82c 100644 (file)
@@ -1150,6 +1150,7 @@ int connect_server(struct stream *s)
        int reuse_orphan = 0;
        int init_mux = 0;
        int err;
+       int was_unused = 0;
 
 
        /* This will catch some corner cases such as lying connections resulting from
@@ -1208,17 +1209,20 @@ int connect_server(struct stream *s)
                             s->txn && (s->txn->flags & TX_NOT_FIRST)) &&
                            srv->curr_idle_nb > 0) {
                                srv_conn = conn_backend_get(srv, 0);
+                               was_unused = 1;
                        }
                        else if (srv->safe_conns &&
                                 ((s->txn && (s->txn->flags & TX_NOT_FIRST)) ||
                                  (s->be->options & PR_O_REUSE_MASK) >= PR_O_REUSE_AGGR) &&
                                 srv->curr_safe_nb > 0) {
                                srv_conn = conn_backend_get(srv, 1);
+                               was_unused = 1;
                        }
                        else if (srv->idle_conns &&
                                 ((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS) &&
                                 srv->curr_idle_nb > 0) {
                                srv_conn = conn_backend_get(srv, 0);
+                               was_unused = 1;
                        }
                        /* If we've picked a connection from the pool, we now have to
                         * detach it. We may have to get rid of the previous idle
@@ -1340,12 +1344,13 @@ int connect_server(struct stream *s)
        /* no reuse or failed to reuse the connection above, pick a new one */
        if (!srv_conn) {
                srv_conn = conn_new();
+               was_unused = 1;
                if (srv_conn)
                        srv_conn->target = s->target;
                srv_cs = NULL;
        }
 
-       if (srv_conn && srv) {
+       if (srv_conn && srv && was_unused) {
                _HA_ATOMIC_ADD(&srv->curr_used_conns, 1);
                /* It's ok not to do that atomically, we don't need an
                 * exact max.