Skip to content

Shielded: ShieldedSyncManager::stop() is cancel-only, not a quiescence barrier (Clear-flow race) #3706

Open

Description

@QuantumExplorer

What

ShieldedSyncManager::stop() (packages/rs-platform-wallet/src/manager/shielded_sync.rs) takes the cancellation token and calls cancel(). That prevents future loop iterations from starting, but does not join the background thread or await an in-flight coordinator.sync() pass.

Why it needs fixing

The method name + doc read like a synchronization barrier, but it's best-effort cancellation. A pass that already snapshotted the subwallet list can run to completion after stop() returns and reach the persister fan-out, queuing changesets.

This bites the Clear flow: platform_wallet_manager_shielded_clear's doc says "stop the loop first so the next pass can't race the registry clear", but because stop() doesn't actually wait, an in-flight pass can re-create PersistentShieldedNote / PersistentShieldedSyncState rows after the host's SwiftData wipe — the exact symptom Clear is meant to prevent. (Narrowed window, not guaranteed, hence suggestion-level.)

Fix

Either give stop() real quiescence (await the running pass before returning) and keep the Clear contract honest, or rename it to cancel() and add a separate quiesce() that the Clear flow calls. Needs care around the dedicated OS thread the sync loop runs on and the is_syncing flag.

Deferred from #3603 review (thepastaclaw).

Activity

  1. QuantumExplorer commented on May 20, 2026

    @QuantumExplorer
    MemberAuthor

    Additional surface from the fd934ba review: the stop() cancel-only gap also affects the rebind path added in fd934ba. bind_shielded now calls coordinator.unregister_wallet(self.wallet_id) before register_wallet + restore_for_wallet, but a concurrent in-flight coordinator.sync() pass that already snapshotted the prior accounts/subwallets can still write to the persister between the unregister and the restore — re-introducing exactly the stale state the rebind purge was meant to clear.

    So a proper quiescence/drain primitive (await the in-flight pass) is needed by three flows, not two: Clear, remove_wallet, and rebind.

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

    bugplatform-wallet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions