fix(pico): reject truncated SCPI responses and close the socket on a failed Wi-Fi connect - #291
thisisanubhav wants to merge 3 commits into
Conversation
pyserial's readline() returns whatever arrived before the timeout, so a
response cut off mid-line ("12" of "123\n") was returned by query() as
a complete answer. Require the line terminator in query() and in the
text error line read by read_block(), and raise ScpiTimeoutError
otherwise, which is what the Wi-Fi transport already does.
PicoWifiTransport.connect() left the socket open if connect() raised (connection refused or timed out), leaking one socket per attempt against an unreachable bridge.
Reviewer's GuideThe PR hardens Pico SCPI and Wi-Fi transport failure handling by rejecting unterminated responses as timeouts and closing sockets when connection setup fails, with focused regression coverage using the existing test fakes. Sequence diagram for truncated SCPI response handlingsequenceDiagram
participant Client as ScpiClient
participant Transport as SCPI transport
Client->>Transport: readline()
alt response ends with newline
Transport-->>Client: response bytes
Client-->>Client: decode and strip
else response is truncated
Transport-->>Client: partial bytes
Client-->>Client: raise ScpiTimeoutError
end
Sequence diagram for failed Wi-Fi connection cleanupsequenceDiagram
participant Client as PicoWifiTransport
participant Socket as Wi-Fi socket
Client->>Socket: socket()
Client->>Socket: settimeout(timeout)
Client->>Socket: connect(host, port)
alt connection succeeds
Client->>Client: store socket
else connect() raises
Client->>Socket: close()
Client-->>Client: re-raise exception
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthrough
ChangesTransport error handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The transport now rejects incomplete SCPI responses and closes sockets after failed Wi-Fi setup. No concrete production risk blocks merging this change. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #290
Changes
ScpiClient.query()now requires the response to end with\n, and raisesScpiTimeoutErrorotherwise. On USB, pyserial'sreadline()returns whatever arrived before the timeout, so a cut-off"12"of"123\n"used to be returned as a valid answer. The Wi-Fi transport already behaved this way. The text error line inread_block()gets the same check.PicoWifiTransport.connect()closes the socket ifconnect()raises, instead of leaking one socket per failed attempt.tests/test_pico_scpi_transport.py.Testing
pytest tests/test_pico_scpi_transport.py: 21 passed. Againstmain'stransport.py, the 3 new tests fail.flake8is clean on the changed files.pslab/picoisn't in the tox lint set, andblack --checkalready flags one line there onmain; I left that untouched to keep the diff focused.No UI changes.
Summary by Sourcery
Ensure incomplete SCPI responses time out and failed Wi-Fi connections release their sockets.
Bug Fixes:
Tests:
Summary by CodeRabbit
Bug Fixes
Tests