Repository navigation
tcp: add removable full-close cancellation registration - #5
Open
polaris-arch wants to merge 4 commits into
Open
polaris-arch wants to merge 4 commits into
polaris-arch wants to merge 4 commits into
Conversation
polaris-arch
marked this pull request as draft
November 9, 2026 11:43
polaris-arch
marked this pull request as ready for review
November 9, 2026 12:26
polaris-arch
marked this pull request as draft
November 9, 2026 14:10
polaris-arch
marked this pull request as ready for review
November 10, 2026 14:26
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.
Add removable full-close cancellation registration for work associated with a TCP connection:
TCPConn.CancelOnClose(context.CancelFunc) func() bool.Classification and normal-path reachability
This is a new optional lifecycle capability, not a demonstrated defect in ordinary TCP read/write behavior. Baseline
9a80a07ehas no equivalent removable full-close notification. External work is affected only when a consumer explicitly registers it; an undefined-method baseline compile error is not a BUG reproduction.A valid peer RST makes the established actor return an error;
run/runPassive/runForwardedPassivecallfinish, which detaches registrations. Full applicationClosedetaches before positive-linger waiting. Callbacks run synchronously outside the existing connection mutex, including registration after termination; they must only signal cancellation and must not wait for the actor/stack.FIN,
CloseRead,CloseWriteand I/O deadlines alone do not imply full termination. Notification does not itself discard queued reads. Source: registration implementation, Close/actor termination.Ownership and minimal implementation
Active-list membership under the existing connection mutex is the ownership authority. A successful stop unlinks its node and clears references. Closure detaches the whole list under that same mutex before invoking callbacks, so a detached node loses stop even if its callback has not run. The notifier exclusively owns detached nodes and releases their references. No separate
claimedflag, marking pass, watcher goroutine or global registry is needed.Multiple independent registrations remain supported; no new duplicate-registration rejection/panic contract is introduced. A false stop means claimed or already removed, does not wait for callback completion and does not establish that the callback has run. The original actor
doneevent is not equivalent to full application closure before linger; a wrapper observing only applicationClosewould miss remote RST termination.Executable capability tests
In a disposable checkout, using the recorded Go 1.26.10 toolchain:
Controlled protocol tests versus fault injection
Final source
5b6706ccpasses focused tests, race checks, full tests, vet and Windows/macOS compilation in exact-source validation. That run also passes real native-forwarder reset/FIN controls and full Mihomo default/with_gvisor, race, vet and tunnel cross-compilation with the preceding TFO/group patches, using a test-only dependency override.Consumer MetaCubeX/mihomo#3438 still needs API acceptance and a production dependency-version update. No production event frequency, standalone process resource saving, or old-API performance comparison is claimed. The source review and exact-source validation are complete. The consumer dependency-version update belongs to #3438; it is not delivered by this API proposal.