You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2026/09/14 11:58:00 UTC

[jira] [Commented] (OFBIZ-13585) Harden testServiceDeadLockRetry to remove timing-dependent Thread.sleep in service engine tests

    [ https://issues.apache.org/jira/browse/OFBIZ-13585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18115135#comment-18115135 ] 

ASF subversion and git services commented on OFBIZ-13585:
---------------------------------------------------------

Commit 8911dbe6193cc712c544be0414508ddde7054bb9 in ofbiz-framework's branch refs/heads/trunk from Mridul Pathak
[ https://gitbox.apache.org/repos/asf?p=ofbiz-framework.git;h=8911dbe619 ]

Fixed: Timing-dependent deadlock-retry test in service engine (OFBIZ-13585)

testServiceDeadLockRetryThreadA/ThreadB relied on a fixed Thread.sleep(100) to force two concurrent threads into a circular-wait deadlock, which is inherently timing-dependent, and a database version change shifted internal timings enough that the two threads no longer reliably collided, causing service-dead-lock-retry-assert-data to fail intermittently.

Replaced the sleep with two CountDownLatch(1) instances, one per thread: each thread signals its own latch once it holds its lock, then waits on the other thread's latch before attempting the second lock, guaranteeing the circular wait deterministically. A latch is used rather than a barrier-style rendezvous because the service engine's own deadlock-retry loop retries only the losing thread's service call in isolation after a real deadlock, not both threads together, and a primitive requiring all parties to rendezvous on every call would block a retried thread waiting on a partner that already moved on and will not synchronize again; a latch already at zero returns immediately, so a retried thread proceeds without waiting for a rendezvous that will never happen.

Verified with 20 repeated runs of the service component test suite.


> Harden testServiceDeadLockRetry to remove timing-dependent Thread.sleep in service engine tests
> -----------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-13585
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-13585
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework/service
>    Affects Versions: Upcoming Branch, 24.09.07
>            Reporter: Mridul Pathak
>            Assignee: Mridul Pathak
>            Priority: Minor
>
> The service engine's deadlock-retry test (testServiceDeadLockRetryThreadA / ThreadB in ServiceEngineTestServices.java) relies on a fixed Thread.sleep(100) to make two concurrent threads race into a circular-wait deadlock. This is inherently timing-dependent: it worked reliably against the database timings this test suite has historically run under, but a database version change (encountered while evaluating a H2 database upgrade) shifted internal timings enough that the two threads no longer reliably collided, causing service-dead-lock-retry-assert-data to fail intermittently.
> This ticket hardens the test to use real thread synchronization instead of a sleep, so the deadlock is triggered deterministically regardless of the underlying database's timing.
> h3. Root cause detail
> Each thread now signals a {{CountDownLatch(1)}} once it holds its own lock, then waits on the other thread's latch before attempting the second lock, guaranteeing the circular wait instead of guessing at timing.
> A latch is required rather than a barrier-style rendezvous: {{ServiceDispatcher.runSync}}'s own deadlock-retry loop retries only the losing thread's service call in isolation after a real deadlock, not both threads together. A synchronization primitive that requires all parties to rendezvous on every call would block a retried thread indefinitely waiting for a partner (the winning thread) that has already moved on and will not synchronize again. A latch avoids this: {{countDown()}} on an already-tripped latch is a no-op and {{await()}} on one returns immediately, so a retried thread proceeds without waiting for a rendezvous that will never happen.
> h3. Testing
> * The original Thread.sleep(100) version fails intermittently under the changed database timing.
> * The CountDownLatch version passed 20/20 repeated component=service runs, with each run completing quickly and no timeout stalls.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)