Fix deadlock: lock subconscious before store (store is bottom-most)

subconscious_snapshots() was acquiring store→subconscious while
collect_results() holds subconscious→store — classic ABBA deadlock.

Fix: always acquire subconscious first, store second. Store is the
bottom-most lock in the ordering.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 19:27:36 -04:00
parent 27ca3c058d
commit bef1bfbb33

View file

@ -249,12 +249,14 @@ impl Mind {
/// Initialize — restore log, start daemons and background agents.
pub async fn subconscious_snapshots(&self) -> Vec<SubconsciousSnapshot> {
// Lock ordering: subconscious → store (store is bottom-most).
let sub = self.subconscious.lock().await;
let store = crate::store::Store::cached().await.ok();
let store_guard = match &store {
Some(s) => Some(s.lock().await),
None => None,
};
self.subconscious.lock().await.snapshots(store_guard.as_deref())
sub.snapshots(store_guard.as_deref())
}
pub async fn subconscious_walked(&self) -> Vec<String> {