Skip to content

platform-wallet: SPV stop waits without bound for a broadcast awaiting acceptance #5192

Open

Description

@llbartekll

Problem

SpvRuntime::stop (packages/rs-platform-wallet/src/spv/runtime.rs) takes the client with self.client.write().await, which waits for every read guard. broadcast_transaction_and_wait holds one for its whole acceptance wait, which is the caller's timeout (the asset-lock orchestration passes 180 s). A stop during such a broadcast (network switch, wipe, manager destroy) waits for it with no bound, and every start meanwhile is refused because a stop is in progress.

What does not work

Tried in #4994 (989b42b) and reverted (eb68b5d):

  • Cloning the client and dropping the guard before the acceptance wait keeps the storage, and its data-dir lock, alive after stop() returns OK, so the next start or storage clear fails with DirectoryLocked.
  • It also lets a broadcast overlap the client stop. The transaction goes to a client whose coordinator has stopped, the wait ends Uncertain, and SpvBroadcaster reports MaybeSent for a transaction that never left; its inputs stay reserved until the reservation TTL.
  • Bounding the lock wait with a timeout that then falls through to the run-loop join aborts a healthy run loop, leaving a started client with no loop.

Direction

A broadcast gate: stop closes it first, so new broadcasts are rejected as never sent, then drains the in-flight ones within its budget. Decide what an in-flight acceptance wait reports when the stop budget runs out.

Raised in review of #4994: #4994 (comment)

🤖 Generated with Claude Code

Activity

  1. PastaPastaPasta commented on Nov 3, 2026

    @PastaPastaPasta
    Member

    A data point from a desktop consumer of rs-platform-wallet, in case it helps prioritise this. It's measured on a single-peer regtest, so no peer other than the recipient can echo, and there's no InstantSend quorum.

    • With timeout: None (SpvBroadcaster::broadcast), the wait runs for dash-spv's own broadcast_acceptance_timeout (60 s) plus grace. A SpvRuntime stop that started during a resend's wait took 63 s to return.
    • In the app this showed up as a quit, and a CLI command's shutdown, taking about a minute. That's a delay rather than a correctness problem, because the stop does complete.

    On our side we now abort our own detached acceptance wait before shutting the manager down. That covers only our resend task. Any other broadcast still waiting when a stop starts still holds it, so the broadcast gate described above is what would fix it in general.


    🤖 Posted autonomously by Claude on behalf of pasta.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions