Skip to content

Restore the stored settings when reconfigure_port fails - #160

Open
Happyfield7 wants to merge 1 commit into
puddly:devfrom
Happyfield7:restore-settings-on-failed-reconfigure
Open

Happyfield7 wants to merge 1 commit into
puddly:devfrom
Happyfield7:restore-settings-on-failed-reconfigure

Conversation

@Happyfield7

Copy link
Copy Markdown
Contributor

Problem

reconfigure_port() stores the new settings before applying them and keeps them when applying raises. Backends that rebuild the configuration from the stored settings then fail on every later call. On a POSIX port without RTS/CTS support, reconfigure_port(rtscts=True) correctly raises UnsupportedSetting, but a following reconfigure_port(baudrate=19200) raises the same error, baudrate reports 19200 while the line stays at 9600, and reopening the port fails too.

Change

BaseSerial._staged_settings() stores the update for the backend to read and restores the changed fields if applying raises, re-raising the original error. The sync and async reconfigure_port() and the deprecated setters use it. A cancelled async reconfigure keeps the new values, since the executor may still apply them. The old settings are not reapplied to the port, because a second error could hide the first; if a backend fails after part of the update already reached the port (possible on Win32 and RFC 2217), the stored values can differ from the port for those fields.

Testing

Unit tests with a stub backend cover the sync path and the deprecated setters; pty tests reproduce the case above on the sync and async API and check the line speed, and one checks that a cancelled reconfigure keeps the new values. The four bug tests fail without the change. Full suite passes on macOS and Debian sid.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.48%. Comparing base (2c500d7) to head (6784021).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #160      +/-   ##
==========================================
+ Coverage   94.38%   94.48%   +0.09%     
==========================================
  Files          25       25              
  Lines        4437     4457      +20     
==========================================
+ Hits         4188     4211      +23     
+ Misses        249      246       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant