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

Add SQL concurrency check to key manager state set_index #6081

Open
stringhandler opened this issue Jan 17, 2024 · 0 comments
Open

Add SQL concurrency check to key manager state set_index #6081

stringhandler opened this issue Jan 17, 2024 · 0 comments

Comments

@stringhandler
Copy link
Collaborator

stringhandler commented Jan 17, 2024

Regarding this code:

pub fn set_index(id: i32, index: Vec<u8>, conn: &mut SqliteConnection) -> Result<(), KeyManagerStorageError> {

Expected:
The SQL update should have a where clause protecting against concurrent writes. If thread1 reads the index, then thread2 reads the index and then thread2 writes before thread1, then thread1 should fail when it tries to write.
This is easily achieved by passing in the old value and adding a where clause to check the value is still what was read. Then the method can fail if the SQL affects no rows.

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

No branches or pull requests

1 participant