Repository navigation
Description
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
- swift-sdk: an async
deleteWallet(walletId:)that runs the native removal off the main actor, like the asyncstopSpv()(fix(swift-sdk): stop SPV off the main thread #4994) andstopShieldedSync()(fix(swift-sdk): stop shielded sync off the main thread #5202). That removes the freeze; the deletion itself still waits for the pass. - rs-platform-wallet: a pass that notices cancellation (platform-wallet: shielded sync stop and manager destroy wait for a whole in-flight pass #5200) would let the removal stop the pass instead of waiting for it.
Related
- platform-wallet: shielded sync stop and manager destroy wait for a whole in-flight pass #5200: a shielded pass cannot be cancelled, so stop and destroy wait for it.
- platform-wallet-ffi: SPV stop holds the manager registry read guard for its whole run #5191: the SPV stop holds the manager registry's read guard for its whole run.
- swift-sdk: stopShieldedSync() blocks the main actor for up to 10 s #5201 / fix(swift-sdk): stop shielded sync off the main thread #5202: the async
stopShieldedSync(). - fix(syncing): stop shielded sync off the main thread on every path dashwallet-ios#1171 moved the app's shielded stop off the main actor on every path. It lists this issue under "Not changed here".
🤖 Generated with Claude Code
Activity