Skip to content

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

Merged
mridulpathak merged 1 commit into
apache:release24.09from
mridulpathak:OFBIZ-13585-release24.09
Sep 14, 2026
Merged

mridulpathak merged 1 commit into
apache:release24.09from
mridulpathak:OFBIZ-13585-release24.09

Conversation

@mridulpathak

Copy link
Copy Markdown
Contributor

Backported from trunk (#1985).

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 10 repeated runs of the service component test suite on release24.09's Derby-based embedded database.

…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.
@mridulpathak
mridulpathak merged commit 2ccd4d0 into apache:release24.09 Sep 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants