[xwiki/xwiki-commons] 87d141: XCOMMONS-2092: Fix the real root cause: a concurre...
Branch: refs/heads/XCOMMONS-2092 Home: https://github.com/xwiki/xwiki-commons Commit: 87d141e0e5838431fece272f9f77aca5eb594deb https://github.com/xwiki/xwiki-commons/commit/87d141e0e5838431fece272f9f77ac... Author: Simon Urli <[email protected]> Date: 2026-09-10 (Thu, 10 Sep 2026) Changed paths: M xwiki-commons-core/xwiki-commons-job/xwiki-commons-job-default/src/main/java/org/xwiki/job/internal/ReadWriteSemaphore.java M xwiki-commons-core/xwiki-commons-job/xwiki-commons-job-default/src/test/java/org/xwiki/job/internal/DefaultJobExecutorTest.java Log Message: ----------- XCOMMONS-2092: Fix the real root cause: a concurrency bug in ReadWriteSemaphore The previous commit worked around the flicker with a Thread.sleep in the test, but that only narrowed one particular timing window instead of fixing the actual bug. This replaces it with a fix in production code and removes the workaround, which is no longer needed. * ReadWriteSemaphore#lockWrite/unlockWrite/lockRead/unlockRead mutated writeCounter/readCounter with incrementAndGet()/decrementAndGet() and then made the permits decision from a separate, later get() call, letting concurrent callers race and compute the wrong number of permits to acquire or release; a stress test hammering the same parent/child pool shape as the flaky test (pool sizes 1 and 2) reliably deadlocked within a couple hundred operations because of this * Guard the counter mutation and the resulting permit-count decision with an internal lock so each call makes its decision atomically; the lock is released before the (possibly blocking) semaphore acquire/release, so a thread waiting for a permit never holds a lock another thread needs in order to release one * Revert the Thread.sleep workaround added in the previous commit: it is no longer necessary with the real fix in place * Verified with a stress test reproducing the deadlock against the original code and confirming it cannot reproduce against the fix (5 runs x 3M operations each, no failure), and 500 repetitions of every test in DefaultJobExecutorTest (1500 runs total, 0 failures) Co-Authored-By: Claude Sonnet 5 <[email protected]> To unsubscribe from these emails, change your notification settings at https://github.com/xwiki/xwiki-commons/settings/notifications
participants (1)
-
XWiki Notifications