Repository navigation
Description
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_stoprunsShieldedSyncManager::quiesce(), which cancels the loop and pollsis_syncingfor up toCOORDINATOR_DRAIN_BUDGET(10 s). If the pass is still running, it returnsfalseand the FFI returnsErrorShutdownIncomplete(27).platform_wallet_manager_destroyrunsPlatformWalletManager::shutdown(). That quiesces every coordinator again with the same 10 s budget, then joins the loop threads through the registry, up toDEFAULT_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
- Shielded: ShieldedSyncManager::stop() is cancel-only, not a quiescence barrier (Clear-flow race) #3706:
ShieldedSyncManager::stop()is cancel-only (the Clear-flow race thatquiescewas added for). - platform-wallet: shielded notes sync runs 16 parallel chunk queries, most of them past the end of the tree #4999: a pass runs 16 parallel chunk queries, most of them past the end of the tree.
- Offline network switch blocks the wallet for 41 s: native SDK teardown (destroy) takes 26 s dashwallet-ios#1120: offline,
destroytook 26 s while every stop reported 0 ms. - fix(syncing): let the host teardown stop shielded sync off the main thread dashwallet-ios#1168 (open) removes the app's own run of this stop from the network switch's main thread. The wait in the off-main teardown remains.
🤖 Generated with Claude Code
Activity