Skip to content

Commit

Permalink
Document the small database drop race condition window
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Mar 10, 2022
1 parent b0807b8 commit d8a79b6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zebra-state/src/service/finalized_state/disk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ impl DiskDb {
pub(crate) fn shutdown(&mut self, force: bool) {
// Prevent a race condition where another thread clones the Arc,
// right after we've checked we're the only holder of the Arc.
//
// There is still a small race window after the guard is dropped,
// but if the race happens, it will only cause database errors during shutdown.
let clone_prevention_guard = Arc::get_mut(&mut self.db);

if clone_prevention_guard.is_none() && !force {
Expand Down Expand Up @@ -483,6 +486,9 @@ impl DiskDb {

// Prevent a race condition where another thread clones the Arc,
// right after we've checked we're the only holder of the Arc.
//
// There is still a small race window after the guard is dropped,
// but if the race happens, it will only cause database errors during shutdown.
let clone_prevention_guard = Arc::get_mut(&mut self.db);

if clone_prevention_guard.is_none() && !force {
Expand Down

0 comments on commit d8a79b6

Please sign in to comment.