Skip to content

refactor: merge identical except blocks in _connect_sock cleanup - #229

Merged
bdraco merged 1 commit into
mainfrom
fix/issue-206-duplicate-except-cleanup
May 20, 2026
Merged

bdraco merged 1 commit into
mainfrom
fix/issue-206-duplicate-except-cleanup

Conversation

@bdraco

@bdraco bdraco commented May 20, 2026

Copy link
Copy Markdown
Member

What do these changes do?

_connect_sock had two except blocks whose bodies were byte-for-byte identical except for one line; the only real difference is whether the exception is recorded in my_exceptions. Collapse them into a single except BaseException as exc: with an isinstance((RuntimeError, OSError)) guard around the append, so the 8-line socket teardown lives in one place.

Are there changes in behavior for the user?

No, the merged handler preserves exact semantics; RuntimeError/OSError still land in my_exceptions, everything else (including CancelledError, SystemExit) still runs cleanup and re-raises without being recorded. The existing test_handling_system_exit, test_cancellation_is_not_swallowed, and test_single_addr_info_close_errors cover both branches and stay green.

Related issue number

Closes #206.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fd93f12) to head (e51c41c).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #229   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          250       241    -9     
  Branches        53        52    -1     
=========================================
- Hits           250       241    -9     

☔ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors _connect_sock’s exception handling to remove duplicated socket teardown logic while preserving the previous exception-recording behavior and re-raise semantics.

Changes:

  • Merged the (RuntimeError, OSError) and bare except handlers into a single except BaseException as exc.
  • Preserved behavior by conditionally appending only RuntimeError/OSError to my_exceptions, while still performing identical cleanup and re-raising for all exceptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bdraco
bdraco marked this pull request as ready for review May 20, 2026 16:14
@bdraco
bdraco merged commit b7c186e into main May 20, 2026
27 of 28 checks passed
@bdraco
bdraco deleted the fix/issue-206-duplicate-except-cleanup branch May 20, 2026 16:14

This branch had an error being deployed

1 failed deployment
test_release — e51c41c9 Deployed May 20, 2026 by bdraco via test_release #554
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.

duplication: Identical socket-cleanup logic duplicated across both except blocks in _connect_sock

2 participants