Skip to content

fix(connect_tcp): synchronize server startup, client connections, and retries with terminal shutdown - #26

Merged
F18-Maverick merged 19 commits into
F18-Maverick:mainfrom
F18-Ray:fix_close_setup_race
Dec 1, 2026
Merged

F18-Maverick merged 19 commits into
F18-Maverick:mainfrom
F18-Ray:fix_close_setup_race

Conversation

@F18-Ray

@F18-Ray F18-Ray commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Summary

<What this PR does and which problem it solves, in two or three sentences.>

Change type

  • New feature (Added)
  • Behaviour change (Changed)
  • Feature deprecated (Deprecated)
  • Feature removed (Removed)
  • Bug fix (Fixed)
  • Security fix (Security)
  • Docs / refactor (no user-visible change)

Checklist

  • Local tests pass (pytest)
  • Ruff passes (ruff check)
  • Related docs updated (docstring / .rst / README)
  • Changelog updated (if there is a user-visible change)
  • No new linter suppressions (# noqa / # type: ignore)

Documentation impact

  • No user-visible change
  • Updated docs/source/...
  • Changelog only
  • Needs a follow-up issue #___

Design decisions

  • No significant design decision in this change
  • Added a design note: docs/source/design/___
  • Implicit assumptions to record (explained below)

Design note summary (if any)

<Fill this in when "implicit assumptions to record" is ticked; or link the docs/source/changes/PR-*.md note.>

Check the terminal flag before each outer connect attempt and return False
when close wins between retries. Keep the existing local-port fallback
and the handling of an already started connection attempt unchanged.
Record the control socket and ID of an acquired client port range.
Serialize its release and ignore cleanup for another session or an
already released reservation, so a late close cannot delete a reused ID.

This does not defer range release until all borrowed ports are returned.
Record how to review the three parts of 90567ed against its parent without rewriting the current branch.
Keep A2 gated on A1 review, regression coverage and API documentation. No product or test changes.
Distinguish a refused next attempt from a TCP request already in flight. The A0/B0 V0 baseline passed all nine targeted cases.
Document sequential ID reuse and its distinction from returning a borrowed port. The V0 regression preserves the replacement client’s record after a late close.
Exercise startup after stop, a listening but unpublished socket, a published session and a reader parked before registration, in threaded and asyncio modes. Verify fd retirement, peer EOF, same-address /clients and configuration deletion after the original call returns.
Against the parent the refused-start, candidate-return and unregistered-socket cases each fail in both modes. A1: eight timing cases pass; both complete endpoint test files pass (48 cases) on Linux/Python 3.10.
Distinguish terminal refusal from normal exit and document same-address reuse without restarting the old instance. Preserve the historical E2 report. The Sphinx dummy build completed with two pre-existing warnings.
Add the integration half of A-S alongside the stopped-instance unit cases in 4c045a2. Verify replacement service and terminal cleanup before releasing the old caller or reader.
The parent leaves the pending fd open in both modes and returns None for prepublication refusal. All eight A-S cases pass on the accepted tree; the published-session cases are positive controls.
Complete the documentation delivered with 1b7e117. Keep E2 historical results and Client in-flight behavior out of the Server acceptance claim.
Keep the original fd, EOF and same-address checks. Park the actual running store and observe real lock contention versus completed stop; inspect reader registration before teardown can erase it. Isolate saved progress and outbound logs.
4c045a2 contains the stopped-instance unit test; the first socket integration cases landed in 347cdfb. The final A-S set is ten cases: pre-A1 eight fail and both published-session controls pass; all ten pass on A1. Default progress and outbound-log fixture bytes remain unchanged. Targeted ty check passed.
A0 checks between attempts. A caller past that check can still issue a TCP request after close returns. Link to the generated method reference for exact results.
Explain that the allocator records the then-current control socket, not necessarily a delayed announcement’s source. Duplicate numeric announcements can overwrite that single slot.
Keep lifecycle handoff guidance in the Server API guide and exact outcomes in the method reference and A1 change note. The note identifies the shared configuration wrapper, both accept paths and cleanup lock boundary.
Final Sphinx dummy build exited 0 with the two pre-existing warnings; no change to the historical E2 report.
Track the candidate socket before bind/connect so close() can retire it.
Publish the control socket and reader together. If close() wins during
mode negotiation, return False without starting key exchange or recovery.

Wake negotiation and retry waits on close(). Wait one second before
retrying a refused or timed-out connection, but keep the immediate
fallback to an OS-assigned port when the fixed local port is unavailable.

The private dialing and publication helpers do not change public
signatures. Prior verification on this exact file: 13 V2 regressions,
four adjacent regressions and 30 isolated probes passed on Linux.
The full suite and native Windows/macOS were not run for A2.
Exercise the A2 admission, retry and fixed-port fallback paths. Hold an ordinary connector after the peer accepts and verify that close retires its fd before the caller is released. Check mode refusal, interruptible backoff and stale recovery against the real control-session lifecycle.
Test-only changes across three modules; no product structure or interface changes. Prior Linux/Python 3.10 verification: all 38 targeted cases passed. Of the 17 new cases, 13 failed on the pre-A2 parent and four controls passed. No full-suite or native Windows/macOS run.
Update the Client API guide and A2 change note. Distinguish a TCP request observed by the peer from a published session, EOF before a mode announcement from ordinary disconnect, and immediate local-port fallback from a delayed retry.
Documentation only; no product structure or interface changes. Prior Sphinx dummy build completed with two pre-existing warnings.
A single one-second backoff may call Condition.wait() more than once
with the time remaining before its deadline. Record the timeout passed
to wait_for() and its predicate outcome instead of counting those
individual waits. Keep the exact interval and close-cancellation checks.

Linux: all eight targeted cases passed with early returns injected;
three conditions re-waited with a sub-second remainder. Native Windows
Actions has not been rerun. No product code or CI configuration changed.
A reused address in server.clients does not prove that the client has
published its replacement socket. Wait for new control sockets on both
ends before checking automatic upload and download recovery. Keep the
original timeout, fixed-port assertion and byte-for-byte file checks.

Linux: both tests passed with client publication held until after server
registration. Native Windows Actions has not been rerun.
@F18-Ray
F18-Ray force-pushed the fix_close_setup_race branch from a220fef to 5916f5e Compare December 1, 2026 15:35
@F18-Maverick
F18-Maverick merged commit 7d9538a into F18-Maverick:main Dec 1, 2026
13 of 14 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.25843% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
PyFlow/network_api/connect_tcp.py 93.25% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

3 participants