Repository navigation
DEV-1198 Fix the ShimmerDriverPC connect test hang on Linux CI - #325
Merged
Merged
Conversation
The lns0_16_11_w_sd_bt_streaming connect hangs on Linux CI and not on Windows, so the CI log is the only evidence of where the IO thread is stuck. Print every thread's full stack, the monitors it holds, the lock it waits on and any JVM-detected deadlock before failing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JongChern
marked this pull request as ready for review
October 15, 2026 05:34
The connect sequence unlocks the instruction stack and then starts the read-status timer with no delay, so the timer's first readStatusTask (device lock, then instruction-list lock) runs just as the IOThread takes the first post-connect instruction in getInstruction() (list lock, then device lock). When they meet, both block for good and the connect never finishes. The thread dump from the previous commit shows that cycle on Linux CI in lns0_16_11_w_sd_bt_streaming, and locally in API_0000X_ByteCommunicationShimmer3. The driver is deliberately left unchanged. The simulator tests now build their ShimmerPC through ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer(), which overrides startTimerReadStatus() to do nothing, so nothing else touches the instruction list while the IOThread connects. The tests lose only the 5 s status poll; the connect sequence still reads the status once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JongChern
force-pushed
the
DEV-1198_connect_test_hang
branch
from
October 15, 2026 08:49
3f1060b to
ffb9647
Compare
jyong15
approved these changes
Oct 15, 2026
This was referenced Oct 15, 2026
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.
Fixes the hang that has kept
gradle.ymlred on master and on every PR since #321 merged on 2026-10-12. The failing test wasAPI_0000X_ByteCommunicationShimmer3lns0_16_11_w_sd_bt_streaming.test001_testConnectandDisconnect("Device did not finish initialising within 30000 ms (state: Connecting)").Cause: a lock-order deadlock between the IOThread and the read-status timer
ShimmerBluetooth's instruction list is guarded by two locks: the device's monitor and the list's own. Every path takes them device first, list second (getListofInstructions(),writeInstruction(), …), exceptgetInstruction()on the IOThread. It holds the list's lock and then calls thesynchronizedgetListofInstructions().initializeShimmer3or3R()unlocks the instruction stack and then starts the read-status timer with no delay, just as the IOThread picks up the first post-connect instruction. The timer'sreadStatusTaskcallsgetListofInstructions(), so it takes the two locks the other way round. When they meet, both threads block for good. The connect never finishes, anddisconnect()cannot stop the IOThread ("IOThread did not terminate within join timeout").The thread dump this PR adds shows the cycle on Linux CI (run 38681789546, in
lns0_16_11_w_sd_bt_streaming), and on a local Windows run inAPI_0000X_ByteCommunicationShimmer3:#321 did not cause it. Before #321 each test slept 3-5 s after connecting. Now connects follow one another as soon as each device is initialised, which made the race land on CI every time.
Changes (test code only, the driver is unchanged)
ByteCommunicationTestUtils.connectAndWaitUntilInitialisedprints every thread's full stack, the monitors it holds and any JVM-detected deadlock before failing on a timeout.ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer(), aShimmerPCwhosestartTimerReadStatus()does nothing. That timer is the only other thread touching the instruction list while the IOThread connects: the connect sequence queues its reads while the stack is locked, and the battery timer first fires after 60 s. The tests lose only the 5 s status poll. The connect sequence still reads the status once.No timeouts were raised and no tests were reordered.
Known limitation
The lock-order inversion is still in the driver. A real LogAndStream device can, rarely, stick at Connecting when the timer's first run meets the IOThread taking an instruction. Changing the driver's IO path was ruled out for this PR.
Verification
lns0_16_11_w_sd_only,w_sync_master,w_sync_slave) stay excluded here. Re-enabling them is a separate PR, so a failure in them cannot turn master red.Other APIs
None need this: the change is confined to ShimmerDriverPC's tests.
🤖 Generated with Claude Code