Repository navigation
Description
TL;DR: Stopping the wallet's network sync can report success a moment before the sync data folder is actually released, so clearing the data or starting again right away can fail once.
User story
As a wallet app developer, I want a finished stop to mean the sync data is free to reuse, to achieve a clear-and-restart that works on the first attempt.
Scenario
Base flow
Sync fails on its own or detects a chain reorganization. At the same moment the app asks the wallet to stop, then immediately clears the sync data or starts sync again.
Actual behavior
Stop returns successfully, but the clear or the start that follows can fail with a "directory locked" error. Retrying a moment later works.
Expected behavior
Once stop returns successfully, clearing the sync data and starting again succeed.
Detailed discussion
Raised by review on #5307 (packages/rs-platform-wallet/src/spv/runtime.rs, the teardown closure that sets Shutdown::Idle).
In dash-spv (client/sync_coordinator.rs, rust-dashcore dev at d036d844) the sync loop detaches two helper tasks, each holding a clone of the client:
- on a sync error:
tokio::spawn(async move { client.stop_failed().await }) - on
SyncEvent::ForkDetected:tokio::spawn(async move { client.handle_fork(fork_height).await })
DashSpvClient::stop joins the sync-loop task and stops the managers, but not these helpers. When an explicit stop takes the sync_loop mutex while the loop is finishing an error or a fork, the helper waits behind it and is still alive, with its client clone and therefore the storage Arc, after stop returns. DiskStorageManager holds its directory lock file until the storage object is dropped, so clear_storage() or start() issued right after can return DirectoryLocked.
Impact is a transient failure of an immediate clear or restart. No data corruption has been shown.
Options:
- Upstream: track the helper tasks and join them in
stop(preferred; the tasks are private todash-spv). - Platform: an ownership-release barrier in
SpvRuntimebefore teardown is declared complete.
Either way, add a regression test that races a background failure / fork against stop followed by an immediate clear and restart. The existing background-failure test yields 1,000 times before stopping and does not exercise this ordering.
Prior work
- chore(platform)!: update rust-dashcore (incl secp256k1 0.33) #5307 — where the review raised it.
- fix(platform-wallet)!: tell a retryable SPV stop from one that needs a restart #5322 — distinguishes a retryable SPV stop from one that needs a restart.
Attribution
🤖 Co-authored by Claudius the Magnificent AI Agent
Activity