Fix ISOTPSoftSocket.select() dropping ObjectPipe, causing sr1() to hang (fix #4838)#4929
Open
BenGardiner wants to merge 1 commit intosecdev:masterfrom
Open
Fix ISOTPSoftSocket.select() dropping ObjectPipe, causing sr1() to hang (fix #4838)#4929BenGardiner wants to merge 1 commit intosecdev:masterfrom
BenGardiner wants to merge 1 commit intosecdev:masterfrom
Conversation
…ng in threaded mode * Fix ISOTPSoftSocket.select() race condition and add threaded sr1 timeout tests The select() method was filtering out ObjectPipe instances (like the sniffer's close_pipe) from its return value. This prevented the sniffer's stop mechanism from working correctly in threaded mode - when sniffer.stop() sent to close_pipe, the select() method would unblock but not return the close_pipe, so the sniffer loop couldn't detect the stop signal and had to rely on continue_sniff timing, causing hangs under load. The fix includes close_pipe (ObjectPipe) instances in the select return value, so the sniffer loop properly detects the stop signal via the 'if s is close_pipe: break' check. Added two new tests: - sr1 timeout with threaded=True (no response scenario) - sr1 timeout with threaded=True and background CAN traffic Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com> * Add deterministic unit test that fails without fix; keep integration tests The new "ISOTPSoftSocket select returns control ObjectPipe" test directly verifies that ISOTPSoftSocket.select() passes through ready ObjectPipe instances (e.g. the sniffer's close_pipe). This test deterministically FAILS without the fix and PASSES with it. The integration tests (sr1 timeout with threaded=True) are kept for end-to-end coverage but the race window is too narrow on Linux with TestSocket to reliably trigger the bug. Verification: - Without fix: "select returns control ObjectPipe" = FAILED - With fix: "select returns control ObjectPipe" = PASSED - All 67 test cases pass with the fix applied Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4929 +/- ##
==========================================
+ Coverage 80.10% 80.64% +0.53%
==========================================
Files 370 370
Lines 91733 91735 +2
==========================================
+ Hits 73482 73976 +494
+ Misses 18251 17759 -492
🚀 New features to boost your workflow:
|
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.
( I worked this out with Copilot / Claude Opus 4.6 here: BenGardiner#1 to try to fix the ISO TP soft socket problem that has been plaguing me )
The select() method was filtering out ObjectPipe instances (like the sniffer's close_pipe) from its return value. This prevented the sniffer's stop mechanism from working correctly in threaded mode - when sniffer.stop() sent to close_pipe, the select() method would unblock but not return the close_pipe, so the sniffer loop couldn't detect the stop signal and had to rely on continue_sniff timing, causing hangs under load.
The fix includes close_pipe (ObjectPipe) instances in the select return value, so the sniffer loop properly detects the stop signal via the 'if s is close_pipe: break' check.
Added unit tests:
The new "ISOTPSoftSocket select returns control ObjectPipe" test directly verifies that ISOTPSoftSocket.select() passes through ready ObjectPipe instances (e.g. the sniffer's close_pipe). This test deterministically FAILS without the fix and PASSES with it.
The integration tests (sr1 timeout with threaded=True) are kept for end-to-end coverage but the race window is too narrow on Linux with TestSocket to reliably trigger the bug.
Verification:
This fixes #4838
The timeouts on slcan for a SF request -> MF response are a pre-existing problem.
NB: copilot/claude also suggested this optimization BenGardiner@8992e1b which seems correct to me but is not directly related to fixing the sr1() hang I've observed. It is not included in this PR.
cc: @polybassa