Skip to content

fix(id-sync): do not hold replica lock while waiting on peer transfer #12636

Closed

Description

@dezren39

Evidence

In pkgs/id/crates/id-sync/src/federation/exchange_net.rs, ExchangeProtocol::session acquires self.replica.lock() at line 700, writes the hello reply at 711, then waits for the remote transfer frame at lines 713–717. The same mutex guard remains live while receiving and processing the transfer and sending the reply (through line 744). The only bound on this wait is the 30-second TIMEOUT around the session in accept (lines 751–754).

A remote peer can complete a valid hello exchange and then stop sending. During that interval, the replica-wide mutex is held, so other sessions for the same ExchangeProtocol cannot read/update the replica and may themselves time out waiting for the lock. This turns one stalled stream into up to 30 seconds of avoidable federation unavailability.

Why it matters

The timeout prevents indefinite lock retention, but serializing unrelated sessions behind a peer-controlled network wait makes a single slow or malicious peer able to delay legitimate synchronization.

Acceptance criteria

  • Do not hold the replica mutex across a peer-controlled read/write wait.
  • Preserve the exchange invariant that both offers are computed from pre-transfer inventories and that received versions are admitted in the defined order.
  • Add a regression test with one session stalled after hello and another healthy session, demonstrating that the healthy session can make progress (or is rejected promptly by a documented bounded-concurrency policy rather than waiting on the replica lock).
  • Keep the per-session timeout and ensure timed-out streams release resources.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    on Nov 22, 2026
  2. developing-today commented on Nov 22, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 22, 2026
  4. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    The requested lock-release fix is in merged PR #12641 (merge commit b52a270). Its two regressions cover progress of a second healthy exchange while one peer stalls and exclude versions admitted after the hello-time snapshot from that session offer. PR body reports the focused tests plus substrate_transport_path, substrate_sync_path, and federation_b09 passing. Closing as implemented.

  5. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Closed as implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions