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.21.21~46^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1311d2d196d381b2170c4b3d54262874a5d424e;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. --- 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 51ebbe99ae1..60eb7f6c25c 100644 --- a/tests/isc/work_test.c +++ b/tests/isc/work_test.c @@ -54,11 +54,7 @@ after_work_cb(void *arg ISC_ATTR_UNUSED) { static void work_enqueue_cb(void *arg ISC_ATTR_UNUSED) { - isc_tid_t tid = isc_loopmgr_nloops() - 1; - - isc_loop_t *loop = isc_loop_get(tid); - - isc_work_enqueue(loop, work_cb, after_work_cb, NULL); + isc_work_enqueue(isc_loop(), work_cb, after_work_cb, NULL); } ISC_RUN_TEST_IMPL(isc_work_enqueue) {