Repository navigation
DEV-1310: deepClone() no longer copies the connection's queues - #338
Merged
Merged
Conversation
ShimmerPC.deepClone() copies a device by serialising it, which takes no lock. On a connected device the timers and the IO thread kept changing the instruction list (and, while streaming, the PC timestamp list and packet queue) during the copy, so deepClone() could throw ConcurrentModificationException and the configure built on it failed. A clone is a copy of the configuration, not of the connection: those three queues are now transient and readObject() gives the copy empty ones. The Java HIL's HilShimmerPC had the same problem with its own log, which the driver's threads append to on every message; its counters are now transient too. Tests: API_00034 clones while a thread queues and retires instructions, and a simulator-connected device while an app reads battery and status; HilShimmerPCTest clones while the driver logs. All three fail on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a Shimmer3 streaming at 256 Hz, about one copy in a hundred threw ConcurrentModificationException in mListofPCTimeStamps, which the IO thread changes for every packet. And the processing thread's packet queue holds packets that can't be serialised, so deepClone() returned null whenever one was waiting. Both tests fail on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
DEV-1310.
ShimmerPC.deepClone()copies a device by serialising it. Consensys's Bluetooth manager configures a connected device from such a copy, and so does the Java HIL. Serialisation takes no lock, so the copy walked lists that the IO thread and the timers were still changing:deepClone():deepClone()returning null: the processing thread's packet queue holdsRawBytePacketWithPCTimeStamp, which isn'tSerializable, so the copy failed whenever a packet was waiting.The fix
A clone is a copy of the configuration, not of the connection. In
ShimmerBluetooth,mListofInstructions,mListofPCTimeStampsandmABQPacketByeArrayare nowtransient, and a newreadObject()gives the copy empty ones. A deserialised object runs no field initialisers, so without it they'd be null.The HIL's
HilShimmerPCgets the same change to its own log and counters (test code). The HIL's 1-in-30 configure failure that led to this ticket was its own log: the driver adds a line to it on every message, and the copy serialised thousands of lines.Tested
Unit tests: every new test fails on master and passes here.
API_00034_DeepCloneWhileBusyTest:HilShimmerPCTest: clone while the driver logs.ShimmerDriverPC (96 tests) and ShimmerDriver (177) pass.
Hardware: a probe copied a connected Shimmer3 (LogAndStream v1.1.7, Classic) the way
deepClone()does, over and over, and named the field being written whenever a copy threw:mListofPCTimeStamps)Not tested: the same probe on a Shimmer3R. The bench unit wasn't answering over Classic. The race is in host-side serialisation of fields the two types share, so it isn't expected to differ.
Other APIs
None of the other host APIs (C#, web SDK, pyshimmer, Swift, shimmer-logandstream) copies a device by serialisation. ShimmerAndroidAPI's
ShimmerandShimmer3BLEAndroiddeepClone()the same way, but both extendShimmerBluetoothand add no live lists of their own, so Android gets this fix through the driver pin (republish and bump).🤖 Generated with Claude Code