1
Fork 0

Fix a race in the query system

This commit is contained in:
John Kåre Alsaker 2023-02-08 19:53:48 +01:00
parent b583ede652
commit 10b08e3c9c

View file

@ -25,7 +25,6 @@ use std::collections::hash_map::Entry;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::mem; use std::mem;
use std::ptr;
use thin_vec::ThinVec; use thin_vec::ThinVec;
use super::QueryConfig; use super::QueryConfig;
@ -250,13 +249,16 @@ where
where where
C: QueryCache<Key = K>, C: QueryCache<Key = K>,
{ {
// We can move out of `self` here because we `mem::forget` it below let key = self.key;
let key = unsafe { ptr::read(&self.key) };
let state = self.state; let state = self.state;
// Forget ourself so our destructor won't poison the query // Forget ourself so our destructor won't poison the query
mem::forget(self); mem::forget(self);
// Mark as complete before we remove the job from the active state
// so no other thread can re-execute this query.
cache.complete(key, result, dep_node_index);
let job = { let job = {
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
let mut lock = state.active.get_shard_by_value(&key).lock(); let mut lock = state.active.get_shard_by_value(&key).lock();
@ -267,7 +269,6 @@ where
QueryResult::Poisoned => panic!(), QueryResult::Poisoned => panic!(),
} }
}; };
cache.complete(key, result, dep_node_index);
job.signal_complete(); job.signal_complete();
} }