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

fix: always acquire numbers lock first #10842

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Sep 11, 2024

possibly the root cause of #10649

lookups by number need to acquire two read locks:

self.numbers
.read()
.last_key_value()
.and_then(|(_, hash)| self.blocks.read().get(hash).cloned())

if writes locks aren't acquired in the same order, we can end up with a deadlock.

this adds some notes on locking, and makes locking order consistent.
we could also remove drop the numbers readlock for these functions before acquiring the blocks readlock, doesn't have an impact really because a miss on hash would result in the provider falling back to disk and by then the block must exist on disk

@mattsse mattsse added the C-bug An unexpected or incorrect behavior label Sep 11, 2024
@mattsse mattsse changed the title fix: always aquire numbers lock first fix: always acquire numbers lock first Sep 11, 2024
Comment on lines 151 to 155
// acquire locks, starting with the numbers lock
let mut numbers = self.in_memory_state.numbers.write();
let mut blocks = self.in_memory_state.blocks.write();
blocks.clear();
numbers.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call clear directly w/o assigning guard to the variable

@mattsse mattsse enabled auto-merge September 11, 2024 14:14
@mattsse mattsse added this pull request to the merge queue Sep 11, 2024
Merged via the queue into main with commit 6ed0ca5 Sep 11, 2024
34 checks passed
@mattsse mattsse deleted the matt/bad-write-lock-order-on-updates branch September 11, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants