Skip to content

swift-sdk: deleteWallet(walletId:) blocks the main actor while a shielded pass runs #5221

Open

Description

@llbartekll

Problem

PlatformWalletManager.deleteWallet(walletId:) is synchronous and runs on the main actor. It calls platform_wallet_manager_remove_wallet, which block_ons remove_wallet_and_tear_down_generation on the calling thread inside PLATFORM_WALLET_MANAGER_STORAGE.with_item.

The removal detaches the wallet's shielded state. NetworkShieldedCoordinator::unregister_wallet (packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs) takes self.store.write() to purge the wallet's per-subwallet store state.

A shielded pass holds that same write lock for its whole note sync. sync_notes_across (packages/rs-platform-wallet/src/wallet/shielded/sync.rs) acquires it "for the whole interleaved consume", across stream.next().await, so across the SDK's network fetches.

Deleting a wallet while a shielded pass runs therefore blocks the main thread until that pass finishes.

Stopping the loop first does not help. stopShieldedSync() gives up after COORDINATOR_DRAIN_BUDGET (10 s) with ErrorShutdownIncomplete, while the pass keeps running and keeps the lock (#5200).

While the removal waits, it also holds the manager registry's read guard. A registry writer queued behind it (a manager configure or destroy) parks, and because parking_lot's RwLock is task-fair, every other FFI registry read then blocks too. This is the same shape as #5191.

Where it shows up

Dash Wallet iOS deletes wallets through the synchronous deleteWallet on the main actor, both in the full wipe and when removing one wallet (SwiftDashSDKWalletWiper). In both flows the live manager's shielded loop is still running when the deletion runs, so a pass in flight at that moment freezes the UI for as long as the pass still has left. #5200 measured passes that outlived a 10 s stop and kept destroy waiting for up to 37 s.

Found by reading the code on v4.2-dev (4d3c193abc); not measured yet.

Direction

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