Skip to content

platform-wallet: shielded sync stop and manager destroy wait for a whole in-flight pass #5200

Closed

Description

@llbartekll

Problem

A shielded sync pass has no cancellation point, so stopping the loop or destroying the manager waits for any pass that is already running.

  • platform_wallet_manager_shielded_sync_stop runs ShieldedSyncManager::quiesce(), which cancels the loop and polls is_syncing for up to COORDINATOR_DRAIN_BUDGET (10 s). If the pass is still running, it returns false and the FFI returns ErrorShutdownIncomplete (27).
  • platform_wallet_manager_destroy runs PlatformWalletManager::shutdown(). That quiesces every coordinator again with the same 10 s budget, then joins the loop threads through the registry, up to DEFAULT_JOIN_BUDGET (30 s) per worker.
  • The pass itself, ShieldedSyncManager::sync_now → NetworkShieldedCoordinator::sync(force), takes no cancellation token and never checks one. Only the loop's sleep between passes observes cancellation.

Measured

These are host teardowns during dashwallet-ios network switches (iPhone 17 simulator, SDK at bb4e7de380). swift-sdk's PlatformWalletManager.shutdown() runs shielded_sync_stop first, then the other stops and destroy. The other stops took 0 ms in every run.

Shielded pass in flight shielded_sync_stop destroy Teardown
yes (*) 10022 ms, code 27 37029 ms 47.1 s
yes (*) 10011 ms, code 27 22406 ms 32.4 s
yes 10012 ms, code 27 6710 ms 16.7 s
yes 10008 ms, code 27 17112 ms 27.1 s
yes, finished during the stop (*) 7241 ms, code 0 0 ms 7.2 s
no (3 runs) 0 ms, code 0 1–5 ms ≤ 5 ms

(*) The app had run the same stop on its main thread just before, for 10 s (code 27).

destroy is fast once the pass has finished and takes up to 37 s while it has not. The network switch waits for this teardown: the two slowest switches took 62 s and 51 s, of which 57 s and 42 s went to waiting for the pass (the app's stop plus the teardown).

The FFI was built with build_ios.sh --profile dev (dev-ios, unoptimized), so the CPU-bound part of a pass runs slower than in a release build. The waiting does not depend on the build: stop and destroy wait for whatever the pass still has left.

Direction

Let a pass notice cancellation. Check the loop's token between its steps (per wallet, per chunk batch, before the persister fan-out) and drop in-flight requests when it fires. Keep quiesce's guarantee that nothing is persisted after it returns. Stop and destroy would then return promptly instead of waiting out the pass.

Related

🤖 Generated with Claude Code

Activity

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