Fixed: Timing-dependent deadlock-retry test in service engine (OFBIZ-13585) - #1989
Merged
mridulpathak merged 1 commit intoSep 14, 2026
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.