context: fix deadlock and panics when resolving parented contexts

set_current held the config RwLock for writing across make_context,
which for a context with a parent re-entered the same lock through
Context::new's global-manager lookup, deadlocking 'pkh context use'.
Context building is now lock-free by construction: make_context
resolves parent chains against a snapshot map (also rejecting parent
cycles), and neither set_current nor remove_context holds a guard
while building a Context.

A corrupt contexts.json no longer aborts every command at manager
init: load falls back to the default local-only config, backs the
corrupt file up to contexts.json.bak so a later save cannot silently
destroy it, and a dangling current/parent context falls back to local
with an error log instead of panicking.
This commit is contained in:
2026-09-16 02:27:11 +02:00
parent 592e98c1e9
commit 6a5c5a7106
7 changed files with 360 additions and 68 deletions
+3 -3
View File
@@ -1336,9 +1336,9 @@ Provides: virtual-thing (= 2.0), plain-virtual
assert!(status.success(), "debian/rules {target} failed");
}
let ctx = std::sync::Arc::new(crate::context::Context::new(
crate::context::ContextConfig::Local,
));
let ctx = std::sync::Arc::new(
crate::context::Context::new(crate::context::ContextConfig::Local).unwrap(),
);
let native_arch = crate::debian::arch::native().unwrap_or_else(|_| "amd64".into());
let opts = crate::build::binary::BinaryMetadataOptions {
profiles,