From: Ondřej Surý Date: Tue, 10 Mar 2026 17:25:37 +0000 (+0100) Subject: Enforce isc_work enqueue loop affinity X-Git-Tag: v9.20.22~33^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d4b96af062397e9de88fa2580da52049aa82f0bc;p=thirdparty%2Fbind9.git 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) --- diff --git a/lib/isc/work.c b/lib/isc/work.c index 4391b2d2fa1..0b7cdf5743d 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 3c126ee613e..5e0184cd522 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) {