Skip to content

fix(sync): make syncOnce cancellation race-safe#204

Open
marcus-pousette wants to merge 1 commit into
sync/app-facing-controllerfrom
fix/sync-once-cancellation
Open

fix(sync): make syncOnce cancellation race-safe#204
marcus-pousette wants to merge 1 commit into
sync/app-facing-controllerfrom
fix/sync-once-cancellation

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

The inbound controller must stop an in-flight SyncPeer.syncOnce when a target times out, disconnects, or is removed. Merely stopping the caller's wait lets responder work continue and can let an asynchronous Hello handler recreate state after cleanup.

This is the protocol prerequisite for #138. It contains no controller or playground code.

Fix

  • Add AbortSignal support to syncOnce and reuse it for subscription reconciliation.
  • Check cancellation across backend reads, auth hooks, RIBLT work, sends, and direct-send batches.
  • Delete the initiator session immediately and send best-effort remote cleanup after Hello was transmitted.
  • Register responder-side per-filter abort controllers before the first asynchronous Hello step.
  • Recheck cancellation before creating sessions, recording upload acknowledgements, or sending each batch.
  • Cancel superseded work for the same transport/filter without affecting other filters.

Clean integration with #191

The port keeps #191's exchangeId, pendingHelloExchanges, transport-owned state, and capability lease checks. Cancellation cleanup is addressed by filterId; it does not restore the old global Hello waiter or misuse direction-owned exchange IDs.

Semantics and fast paths

  • Calls without a signal keep the direct-send and RIBLT paths without cancellation listeners.
  • Cancellation cannot recall valid operations already transmitted or committed; it prevents later work and state resurrection.
  • Cancellation state is scoped by transport and filter and removed when Hello handling finishes.

Size and verification

  • Incremental diff: 3 files, +369/-69.
  • Protocol TypeScript build passes.
  • Full protocol suite: 58/58.
  • Regressions cover pre-abort, delayed responder storage, post-cancel batches, session cleanup, and listener cleanup.

@marcus-pousette marcus-pousette added bug Something isn't working area:sync Sync protocol, reconciliation, transport, discovery, and sync servers labels Jul 12, 2026
@marcus-pousette marcus-pousette force-pushed the fix/sync-once-cancellation branch from a6ed58e to 91ca885 Compare July 12, 2026 14:09
@marcus-pousette marcus-pousette force-pushed the sync/app-facing-controller branch from 7821011 to b1b50a2 Compare July 12, 2026 15:23
@marcus-pousette marcus-pousette force-pushed the fix/sync-once-cancellation branch from 91ca885 to e3d69f3 Compare July 12, 2026 15:23
@marcus-pousette marcus-pousette force-pushed the fix/sync-once-cancellation branch from e3d69f3 to 7f537fe Compare July 13, 2026 16:05
@marcus-pousette marcus-pousette force-pushed the sync/app-facing-controller branch from b1b50a2 to 46cf7ac Compare July 13, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sync Sync protocol, reconciliation, transport, discovery, and sync servers bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant