[master] 48a2a41cb waiter_epoll: Fix locking wrt nwaited counter

Nils Goroll nils.goroll at uplex.de
Mon Sep 30 15:13:05 UTC 2024


commit 48a2a41cbc97498e044af7b7b3545427e3289872
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 30 17:11:46 2024 +0200

    waiter_epoll: Fix locking wrt nwaited counter
    
    Fixes #4204

diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c
index 1a5303221..95bc442f1 100644
--- a/bin/varnishd/waiter/cache_waiter_epoll.c
+++ b/bin/varnishd/waiter/cache_waiter_epoll.c
@@ -132,6 +132,10 @@ vwe_thread(void *priv)
 			CAST_OBJ_NOTNULL(wp, ep->data.ptr, WAITED_MAGIC);
 			Lck_Lock(&vwe->mtx);
 			active = Wait_HeapDelete(w, wp);
+			if (active != 0) {
+				AN(vwe->nwaited);
+				vwe->nwaited--;
+			}
 			Lck_Unlock(&vwe->mtx);
 			if (active == 0) {
 				VSL(SLT_Debug, NO_VXID,
@@ -139,8 +143,6 @@ vwe_thread(void *priv)
 				continue;
 			}
 			AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL));
-			AN(vwe->nwaited);
-			vwe->nwaited--;
 			if (ep->events & EPOLLIN) {
 				if (ep->events & EPOLLRDHUP &&
 				    recv(wp->fd, &c, 1, MSG_PEEK) == 0)


More information about the varnish-commit mailing list