]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: avoid taking the toremove_lock in on dying tasks
authorWilly Tarreau <w@1wt.eu>
Tue, 30 Jun 2020 09:19:23 +0000 (11:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 30 Jun 2020 12:06:19 +0000 (14:06 +0200)
If the owning task is already dying (context was destroyed by h2_takeover)
there's no point taking the lock then removing it later since all the code
in between is conditionned by a non-null context. Let's simplify this.

src/mux_h2.c

index c6634c5b749aca5d6655285105a3ad87dc54f062..5fad272e78024a93723b5a798b750521fff4b21a 100644 (file)
@@ -3705,34 +3705,36 @@ static struct task *h2_timeout_task(struct task *t, void *context, unsigned shor
 
        TRACE_ENTER(H2_EV_H2C_WAKE, h2c ? h2c->conn : NULL);
 
-       if (!expired && h2c) {
-               TRACE_DEVEL("leaving (not expired)", H2_EV_H2C_WAKE, h2c->conn);
-               return t;
-       }
+       if (h2c) {
+               if (!expired) {
+                       TRACE_DEVEL("leaving (not expired)", H2_EV_H2C_WAKE, h2c->conn);
+                       return t;
+               }
 
-       if (h2c && !h2c_may_expire(h2c)) {
-               /* we do still have streams but all of them are idle, waiting
-                * for the data layer, so we must not enforce the timeout here.
-                */
-               t->expire = TICK_ETERNITY;
-               return t;
-       }
+               if (!h2c_may_expire(h2c)) {
+                       /* we do still have streams but all of them are idle, waiting
+                        * for the data layer, so we must not enforce the timeout here.
+                        */
+                       t->expire = TICK_ETERNITY;
+                       return t;
+               }
 
-       /* We're about to destroy the connection, so make sure nobody attempts
-        * to steal it from us.
-        */
-       HA_SPIN_LOCK(OTHER_LOCK, &idle_conns[tid].toremove_lock);
+               /* We're about to destroy the connection, so make sure nobody attempts
+                * to steal it from us.
+                */
+               HA_SPIN_LOCK(OTHER_LOCK, &idle_conns[tid].toremove_lock);
 
-       if (h2c && h2c->conn->flags & CO_FL_LIST_MASK)
-               MT_LIST_DEL(&h2c->conn->list);
+               if (h2c->conn->flags & CO_FL_LIST_MASK)
+                       MT_LIST_DEL(&h2c->conn->list);
 
-       /* Somebody already stole the connection from us, so we should not
-        * free it, we just have to free the task.
-        */
-       if (!t->context)
-               h2c = NULL;
+               /* Somebody already stole the connection from us, so we should not
+                * free it, we just have to free the task.
+                */
+               if (!t->context)
+                       h2c = NULL;
 
-       HA_SPIN_UNLOCK(OTHER_LOCK, &idle_conns[tid].toremove_lock);
+               HA_SPIN_UNLOCK(OTHER_LOCK, &idle_conns[tid].toremove_lock);
+       }
 
        task_destroy(t);