You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
platform-wallet: a cancelled sync worker can run one more pass after Clear/reset completes #6290
A background sync worker that has already passed its cancellation check can still run one full pass after a reset (Clear) has finished.
For platform-address sync this means: a user clears platform-address data, Clear reports success and that sync is stopped, and the cancelled worker then writes a fresh balance snapshot and sync watermark back.
How it happens
The coordinator loop checks cancel.is_cancelled() and then calls the pass. The pass takes the sync slot and checks the admission gate, but does not look at the loop's cancellation token again.
The worker passes cancel.is_cancelled() and is descheduled before it claims the sync slot.
reset_platform_address_sync_state closes admission, cancels the worker, sees an idle slot, resets the wallets, and reopens admission when its guard drops.
The worker resumes, enters through the reopened gate, and runs a pass.
The window is two adjacent statements, so this needs an unlucky preemption, but nothing rules it out.
Scope
Present on v5.2-dev in all five sync coordinators (identity, dashpay, dpns, platform_address, shielded), which each carry their own copy of the loop. Example: packages/rs-platform-wallet/src/manager/platform_address_sync.rs, the is_cancelled() check followed by sync_now().await.
To check when fixing: whether the same interleaving can reach wallet removal, not only Clear. A pass writing for a wallet that no longer exists would be worse than re-fetched balances.
Proposed fix
After #6163 this is one place instead of five: re-check the loop's cancellation token after admission (once the slot is held) in SyncLoop, and skip the pass if it is cancelled. Add a test that parks the worker between the check and admission, runs the reset, and asserts no pass runs afterwards.
Related, same loop
A tick refused because an old pass still holds the slot can be followed by a full-interval sleep instead of the short retry, if that old pass drains before the loop samples the latch. Also unchanged from the old loops; raised in #6163 (comment). Can be fixed together, with a test seam that lets the retry-cadence test observe which delay the worker chose.
Activity