From: Willy Tarreau Date: Thu, 24 Jun 2021 05:26:57 +0000 (+0200) Subject: Revert "MEDIUM: queue: refine the locking in process_srv_queue()" X-Git-Tag: v2.5-dev1~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e76fc3253d8e1982c881e1ea79b03f69b7a0c4f3;p=thirdparty%2Fhaproxy.git Revert "MEDIUM: queue: refine the locking in process_srv_queue()" This reverts commit 1b648c857bb9e0fb857e86838bcca0c9ed01e2bd. The recent changes since 5304669e1 MEDIUM: queue: make pendconn_process_next_strm() only return the pendconn opened a tiny race condition between stream_free() and process_srv_queue(), as the pendconn is accessed outside of the lock, possibly while it's being freed. A different approach is required. --- diff --git a/src/queue.c b/src/queue.c index c9134afb92..d8e73b2181 100644 --- a/src/queue.c +++ b/src/queue.c @@ -340,29 +340,27 @@ void process_srv_queue(struct server *s, int server_locked) int done = 0; int maxconn; + if (!server_locked) + HA_SPIN_LOCK(SERVER_LOCK, &s->lock); + HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock); maxconn = srv_dynamic_maxconn(s); while (s->served < maxconn) { struct pendconn *pc; - if (!server_locked) - HA_SPIN_LOCK(SERVER_LOCK, &s->lock); - HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock); - pc = pendconn_process_next_strm(s, p); - - HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock); - if (!server_locked) - HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); - if (!pc) break; done++; _HA_ATOMIC_INC(&s->served); + stream_add_srv_conn(pc->strm, s); task_wakeup(pc->strm->task, TASK_WOKEN_RES); } + HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock); + if (!server_locked) + HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); _HA_ATOMIC_ADD(&p->served, done);