Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent race conditions when getting list of accounts during scanning #5094

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

andiflabs
Copy link
Contributor

Summary

Calling Wallet.reset() while a scanning is running can sometimes result in race conditions. In particular, WalletScanner may attempt to query account heads at the same time while accounts are being reset, resulting in errors.

This commit fixes the problem by using database transactions (1) while WalletScanner read accounts and (2) while Wallet.reset() updates accounts.

This commit also adds transactions in Wallet.getEarliestHead() and Wallet.getLatestHead(). These methods are not used during scanning, but they suffer from the same kind of problem.

Note that this commit fixes specific race conditions related to getting the list of accounts to scan, but other race conditions that affect scanning may still exist.

Testing Plan

Documentation

N/A

Breaking Change

N/A

@andiflabs andiflabs requested a review from a team as a code owner June 28, 2024 20:18
@andiflabs andiflabs force-pushed the andrea/scanner-queue branch from 6120a33 to 518c427 Compare June 28, 2024 20:41
Calling `Wallet.reset()` while a scanning is running can sometimes
result in race conditions. In particular, `WalletScanner` may attempt to
query account heads at the same time while accounts are being reset,
resulting in errors.

This commit fixes the problem by using database transactions (1) while
`WalletScanner` read accounts and (2) while `Wallet.reset()` updates
accounts.

This commit also adds transactions in `Wallet.getEarliestHead()` and
`Wallet.getLatestHead()`. These methods are not used during scanning,
but they suffer from the same kind of problem.

Note that this commit fixes specific race conditions related to getting
the list of accounts to scan, but other race conditions that affect
scanning may still exist.
@andiflabs andiflabs force-pushed the andrea/wallet-head-tx branch from ac11526 to 0390b5c Compare June 28, 2024 20:42
Base automatically changed from andrea/scanner-queue to staging June 28, 2024 21:02
@NullSoldier
Copy link
Contributor

one day we'll remove the need for this TX and just use a lock that you can take when you are modifying or using accounts.

@andiflabs andiflabs merged commit 2bb8ed2 into staging Jul 2, 2024
10 checks passed
@andiflabs andiflabs deleted the andrea/wallet-head-tx branch July 2, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants