Repository navigation
DEV-1306: a stop's reply no longer retires the wrong instruction - #337
Merged
Merged
Conversation
Every reply path retires the command in flight with removeInstruction(0), taking the head of the instruction list to be the command answered. Two things broke that around a stop: - operationPrepare() cleared the list while the STOP was still in flight. The stop handling, which sleeps 400 ms on the first byte after the STOP, then removed the head in the STOP's place: the first SET_INFOMEM of a configuration started straight after stopStreaming(), the chunk that holds the sampling rate. The unit kept its old rate. operationPrepare() now waits, for up to 3 s, until a command already in flight has been answered and retired, then clears the list. mTransactionCompleted is volatile, so the waiting thread sees it. - The stop handling then let the same byte go on to the ACK processing. When that byte was the unit's ACK, it retired the next instruction as well, a command queued after the stop that was never sent. The stop handling now returns once the stop is handled, and logs when it was answered by its ACK. API_00031_ConfigureStraightAfterStopTest runs the IOThread over an in-memory radio. Without the fix the stop-window configuration sends only chunks 0x0080 and 0x0100, and the command queued behind an ACK-first stop is never sent; with it both pass, as does a configuration after the stop has finished. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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-1306. Two defects in how the driver retires the command in flight around a stop. Found by the Java HIL's new
samplingRatesscenario in #336 (DEV-1305).The problem
Every reply path retires the command in flight with
removeInstruction(0), which assumes the head of the instruction list is the command being answered. Around a stop, two things break that assumption.1. A configuration started straight after
stopStreaming()loses its first SET_INFOMEM. That chunk holds the sampling rate.IOThread.processNotStreamingWaitForAck).operationPrepare()cleared the list withclearAllInstructions(), removing the STOP. The configuration then queued its chunks.The unit kept its old rate, while chunks 1 and 2 and the sensors were written.
On the bench, this happened on both a Shimmer3 (LogAndStream 1.1.7) and a Shimmer3R (1.1.22):
It isn't the firmware: a raw
SET_SAMPLING_RATEsent 0, 50 or 2,000 ms after a STOP was taken 5 of 5 times.2. A stop answered by its ACK first retires two instructions.
processAckFromSetCommandcalledremoveInstruction(0)again.The firmware answers a stop with its ACK first whenever the stop lands between packets. But the driver sends queued commands while streaming only between blocking reads, so its own STOP goes out as a packet starts arriving, and data comes back first. On hardware, this defect needs the stream to be quiet for over 2 s before a stop. The simulator test below covers it.
Both have been there since 2017: the stop handling's
removeInstruction(0)since 2017-05, andoperationPrepare()'s clear since 2017-10.The fix
operationPrepare()waits until a command already in flight has been answered and retired, then clears the list.mTransactionCompletedis nowvolatile, so the waiting thread sees it change.operationPrepare()holding the device's lock, so the wait can't block the IOThread'sremoveInstruction().Tests
API_00031_ConfigureStraightAfterStopTest(new, in CI) runs the IOThread asconnect()starts it, over an in-memory radio that acknowledges every SET.[0x80, 0x100]sent[0x00, 0x80, 0x100]ShimmerDriver177 tests andShimmerDriverPC88, with 0 failures.streamRest,midStreamSet,reconnectLoop,inStream,queueStress,idleStartandsamplingRates. Every configuration made straight after a stop sent chunk 0.Merging
samplingRatesfails, which fails a-Reportrun.ShimmerBluetooth.java, around the GET ACK and in-stream reply paths. The hunks are near each other but don't overlap.The other APIs and the wrappers
IOThreadandoperationPrepare(). It gets the fix through ashimmerdriverpin bump, currently 0.11.7_beta, with no code port.StopStreaming()blocks for about 1 s.set_sampling_rateis refused until the library is READY.🤖 Generated with Claude Code