feat(native): PR1C — teardown ownership, operation barrier, typed disconnect#5
Open
mrmidi wants to merge 1 commit into
Open
feat(native): PR1C — teardown ownership, operation barrier, typed disconnect#5mrmidi wants to merge 1 commit into
mrmidi wants to merge 1 commit into
Conversation
mrmidi
force-pushed
the
pr1c/teardown-ownership
branch
from
July 20, 2026 16:09
4a7c5ca to
e05646a
Compare
…connect Pin fptn submodule to aad9923 (pr1c/teardown-ownership). C++ bridge: - stop() accepts origin (uint16): 1=swift_tunnel_stop, 2=swift_reconnect, 3=native_failure, 4=peer, 255=unknown - Status struct: +disconnect_code, stop_origin, stop_cleanup_completed, active_operations - client_run_thread: local strong pointer, terminal reason stored after Run() returns Swift: - WebsocketDisconnectCode + WebsocketStopOrigin enums in SharedTunnelRuntime (matching C++ ABI values) - TunnelWebSocketTransport protocol: stop(origin:) - Both wrappers: stop(origin:), status mapping for 4 new fields - Provider: existing stop() calls use default .swiftTunnelStop Tests: 24/24 passed. Debug build succeeded.
mrmidi
force-pushed
the
pr1c/teardown-ownership
branch
from
July 20, 2026 16:51
e05646a to
933305e
Compare
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.
PR1C — Native Teardown Ownership
Base:
pr1b/queue-bounds(stacked PR chain)fptn submodule:
aad9923(pr1c/teardown-ownership)Problem solved
Three races in the previous teardown:
Stop()mutated socket/SSL from the stop-caller's thread while coroutines still executed on the strandRun()exited before coroutines completed (detached, no barrier)shared_from_this()prevented destruction but provided no orderingArchitecture: strand-only teardown + operation barrier
Key design decisions
RequestStop()posts onto strandterminal_reason_(uint32 CAS)run_started_guard, no reset ofstop_requested_async_wait; could outlive the barriershared_from_this()this; safe regardless of coroutine frame lifetimeclient_run_thread()stop()may resetwrapper->clientbefore joinDisconnect classification
tcp_errornative_failurewebsocket::error::closed)peer_closedpeerwebsocket_errornative_failurewatchdognative_failurestop()local_stopInvariants
Swift API
WebsocketDisconnectCode/WebsocketStopOriginenums (matching C++ ABI)stop(origin: .swiftTunnelStop)/stop(origin: .swiftReconnect)disconnectCode,stopOrigin,stopCleanupCompleted,activeOperationsVerification
Stack