Repository navigation
feat: allow only one active Connection Attempt - #421
Merged
Merged
Conversation
Connection work per Socket is now exactly one of Idle, one Scheduled Reopen, or one active Connection Attempt, with at most one attached Transport. A new Connection owns the state machine and the Transport; Socket keeps the DDP handshake, liveness and subscription wiring. An attempt spans Transport construction through DDP handshake success, under one absolute Deadline from config.timeout that joining callers inherit. Driver connect() retains or shares one ordinary attempt, internal reopen() owns delayed recovery, and reopenNow() forces one replacement that repeated callers share. Close takes synchronous, unsupersedable ownership, cancels connection work, refuses new connection and DDP work, joins concurrent callers to one 2000 ms Deadline and a void outcome, and leaves the Socket Idle. Socket disconnected is retired; replacement settles DDP waits directly on the ownership change. BREAKING CHANGE: checkAndReopen is removed from IDriver, Driver and the Client with no alias. The unused close option is removed from ISocketOptions; the close Deadline stays fixed at 2000 ms. ADR-0003 and ADR-0009 are superseded by ADR-0014 and ADR-0015.
A Socket's attached Transport is one it could still write on. transportLost left a dead Transport attached when no Connection Attempt was in flight, so send, call, sub and unsub read attachment as liveness and waited out the recovery window before failing. They now fail fast.
4 of 7 tasks
Merged
6 of 10 tasks
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.
Proposed changes
One active Connection Attempt per Socket. Connection work is now exactly one of Idle, one Scheduled Reopen, or one active Connection Attempt, and a Socket owns at most one attached Transport.
A new
Connectionowns the connection-work state machine and the Transport.Socketkeeps the DDP handshake, liveness and subscription wiring. An attempt spans Transport construction through DDP handshake success; Transport open alone is not success. Every retry is a fresh attempt, and only callbacks matching the current attempt change state.connect()retains a usable Transport or starts and shares one ordinary attempt. Internalreopen()owns delayed recovery. PublicreopenNow()forces one immediate replacement, replaces an ordinary attempt once, and repeated calls share the forced attempt rather than churning Transports.config.timeoutstarts at Transport construction and spans connection plus handshake. Joining callers inherit the remaining time; a replacement gets a fresh one.voidoutcome, and leaves the Socket Idle.disconnectedis retired. Replacement settles DDP waits directly on the ownership change rather than through an event.A Transport lost to the peer is now released rather than left attached.
transportLostused to make the lost Transport inert without clearing it, so an attached Transport no longer meant one the Socket could write on:send,call,subandunsubpassed the attachment guard and waited out the recovery window before failing. They now fail fast. ADR-0014 records the rule.A
subscribeissued in that window is dropped silently and never recorded. That is pre-existing and left as is here: it needs a decision on whether asubabandoned before it reached the wire keeps an entry. Tracked in #422.Breaking changes:
checkAndReopenis removed fromIDriver,Driverand the Client with no alias, and the unusedcloseoption is removed fromISocketOptions. The close Deadline stays fixed at 2000 ms.ADR-0003 and ADR-0009 are superseded by ADR-0014 and ADR-0015.
Steps to reproduce
reopenNow()twice while a forced attempt is running and confirm one Transport is constructed, not two.reopenNow()during an ordinary attempt and confirm the ordinary caller rejects with[ddp] connection attempt was superseded before it completedrather than transferring.disconnect()and thenconnect()and confirm the connect is refused while close owns the Socket and admitted once it settles.send()during the recovery window, and confirm it is refused at once rather than after twice the reopen interval.Tests
Errorthrown valuesopen()-only failurelogoutrejection, synthesized close events, late Transport callbacks, final Idle state, re-admissionconnectingfor a joined caller or a retained Transport