Skip to content

feat: allow only one active Connection Attempt - #421

Merged
diegolmello merged 3 commits into
mobilefrom
diegolmello/399
Aug 31, 2026
Merged

diegolmello merged 3 commits into
mobilefrom
diegolmello/399

Conversation

@diegolmello

@diegolmello diegolmello commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

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 Connection owns the connection-work state machine and the Transport. Socket keeps 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.

  • Driver connect() retains a usable Transport or starts and shares one ordinary attempt. Internal reopen() owns delayed recovery. Public reopenNow() forces one immediate replacement, replaces an ordinary attempt once, and repeated calls share the forced attempt rather than churning Transports.
  • One absolute Deadline from config.timeout starts at Transport construction and spans connection plus handshake. Joining callers inherit the remaining time; a replacement gets a fresh one.
  • Close takes synchronous, unsupersedable ownership. It 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 rather than through an event.

A Transport lost to the peer is now released rather than left attached. transportLost used to make the lost Transport inert without clearing it, so an attached Transport no longer meant one the Socket could write on: send, call, sub and unsub passed the attachment guard and waited out the recovery window before failing. They now fail fast. ADR-0014 records the rule.

A subscribe issued in that window is dropped silently and never recorded. That is pre-existing and left as is here: it needs a decision on whether a sub abandoned before it reached the wire keeps an entry. Tracked in #422.

Breaking changes: checkAndReopen is removed from IDriver, Driver and the Client with no alias, and 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.

Steps to reproduce

  • Connect, drop the Transport, and confirm exactly one Scheduled Reopen follows each failed recovery attempt.
  • Call reopenNow() twice while a forced attempt is running and confirm one Transport is constructed, not two.
  • Call reopenNow() during an ordinary attempt and confirm the ordinary caller rejects with [ddp] connection attempt was superseded before it completed rather than transferring.
  • Call disconnect() and then connect() and confirm the connect is refused while close owns the Socket and admitted once it settles.
  • Drop the Transport unexpectedly and call send() during the recovery window, and confirm it is refused at once rather than after twice the reopen interval.

Tests

  • Every state and operation pair of the connection-work matrix, including ordinary and forced joining, one ordinary-to-forced replacement, and Scheduled Reopen consumption
  • One absolute Connection Attempt Deadline spanning Transport connection through handshake, and a fresh Deadline for a replacement
  • Construction failure, handshake failure, transport failure, and non-Error thrown values
  • Exact caller settlement: shared terminal outcome, supersession rejection, no transfer to later work
  • Retry cardinality, including exactly one Scheduled Reopen per failed recovery attempt and none from an open()-only failure
  • Close and disconnect ownership: joined callers, the 2000 ms bound, refusal of new connection and DDP work, logout rejection, synthesized close events, late Transport callbacks, final Idle state, re-admission
  • Lifecycle event cardinality and ordering, including no connecting for a joined caller or a retained Transport
  • One attached Transport across forced replacement and supersession
  • A lost Transport is released, so a send in the recovery window is refused at once and the replacement carries no frame from it
  • Pinging after a loss recovers on the Scheduled Reopen alone and resumes on the replacement
  • Subscription retention across a Reopen and across a failed forced attempt, and refusal after a Close

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

1 participant