From d4b96af062397e9de88fa2580da52049aa82f0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 10 Mar 2026 18:25:37 +0100 Subject: [PATCH] Enforce isc_work enqueue loop affinity Add a REQUIRE(isc_loop() == loop) assertion to isc_work_enqueue() to strictly enforce that work is enqueued from the loop it is assigned to. This loudly prohibits cross-thread queue manipulation before it inevitably turns into a concurrency debugging nightmare. (cherry picked from commit f1311d2d196d381b2170c4b3d54262874a5d424e) --- lib/isc/work.c | 1 + tests/isc/work_test.c | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/isc/work.c b/lib/isc/work.c index 4391b2d2fa..0b7cdf5743 100644 --- a/lib/isc/work.c +++ b/lib/isc/work.c @@ -58,6 +58,7 @@ isc_work_enqueue(isc_loop_t *loop, isc_work_cb work_cb, int r; REQUIRE(VALID_LOOP(loop)); + REQUIRE(isc_loop() == loop); REQUIRE(work_cb != NULL); REQUIRE(after_work_cb != NULL); diff --git a/tests/isc/work_test.c b/tests/isc/work_test.c index 3c126ee613..5e0184cd52 100644 --- a/tests/isc/work_test.c +++ b/tests/isc/work_test.c @@ -56,13 +56,8 @@ after_work_cb(void *arg) { } static void -work_enqueue_cb(void *arg) { - UNUSED(arg); - uint32_t tid = isc_loopmgr_nloops(loopmgr) - 1; - - isc_loop_t *loop = isc_loop_get(loopmgr, tid); - - isc_work_enqueue(loop, work_cb, after_work_cb, loopmgr); +work_enqueue_cb(void *arg ISC_ATTR_UNUSED) { + isc_work_enqueue(isc_loop(), work_cb, after_work_cb, NULL); } ISC_RUN_TEST_IMPL(isc_work_enqueue) {