{"record":{"id":"c2f3109b2c210492","repo":"BigPizzaV3/CodexPlusPlus","slug":"bridge-context-lock-poisoned","errorCode":null,"errorMessage":"bridge context lock poisoned","messagePattern":"bridge context lock poisoned","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/codex-plus-launcher/src/main.rs","lineNumber":43,"sourceCode":"    fn default() -> Self {\n        Self {\n            core: Arc::new(DefaultLaunchHooks::default()),\n            data: Arc::new(LauncherDataService::default()),\n            runtime: Arc::new(LauncherRuntimeService::new(\n                9229,\n                default_user_script_manager(),\n            )),\n            bridge_context: Arc::new(Mutex::new(None)),\n            browser_monitor: Arc::new(Mutex::new(None)),\n        }\n    }\n}\n\nimpl LauncherHooks {\n    fn watchdog_bridge_context(&self) -> anyhow::Result<BridgeContext> {\n        self.bridge_context\n            .lock()\n            .map_err(|_| anyhow::anyhow!(\"bridge context lock poisoned\"))?\n            .clone()\n            .ok_or_else(|| anyhow::anyhow!(\"bridge context is not initialized\"))\n    }\n}\n\n#[tokio::main]\nasync fn main() -> Result<()> {\n    let args = std::env::args().skip(1).collect::<Vec<_>>();\n    let helper_only = args.iter().any(|arg| arg == \"--helper-only\");\n    let options = parse_launch_options(args.iter());\n    if let Err(error) = launcher_main(args, helper_only, options.clone()).await {\n        let _ = codex_plus_core::diagnostic_log::append_diagnostic_log(\n            \"launcher.failed\",\n            json!({\n                \"message\": error.to_string()\n            }),\n        );\n        if !helper_only {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/apps/codex-plus-launcher/src/main.rs#L25-L61","documentation":"watchdog_bridge_context reads the launcher's shared BridgeContext through a std::sync::Mutex. If a thread panicked while holding that mutex, the lock is poisoned and every subsequent lock() returns Err; the launcher converts that into this anyhow error instead of unwrapping. It signals that an earlier panic corrupted the shared watchdog state.","triggerScenarios":"Any thread holding the bridge_context mutex guard panics (e.g. a bug in hook code or a downstream callee that unwraps a None/failed result), after which every watchdog tick calling watchdog_bridge_context fails with this message.","commonSituations":"A one-time panic in the bridge setup/hook path silently poisoning the lock, then every subsequent watchdog restart attempt reporting 'lock poisoned' repeatedly; debugging after an aborted process section.","solutions":["Find and fix the original panic that poisoned the mutex (check logs/panics occurring before the first 'lock poisoned' message).","Use lock().unwrap_or_else(|p| p.into_inner()) to recover the guarded value if the data is still valid despite the panic.","Replace std::sync::Mutex with parking_lot::Mutex (no poisoning) if poisoning is not meaningful here.","Restart the launcher process as a workaround to clear the poisoned state."],"exampleFix":"// before\nself.bridge_context.lock().map_err(|_| anyhow!(\"bridge context lock poisoned\"))?.clone()\n// after\nself.bridge_context.lock().unwrap_or_else(|poisoned| poisoned.into_inner()).clone()\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let ctx = match launcher.watchdog_bridge_context() {\n    Ok(ctx) => ctx,\n    Err(e) if e.to_string().contains(\"lock poisoned\") => { log_panic_root_cause(); return; }\n    Err(e) => return Err(e),\n};","preventionTips":["Never panic while holding a mutex; return Result from guarded sections.","Use lock().unwrap_or_else(|p| p.into_inner()) for trivially recoverable shared state.","Log the first panic's backtrace — subsequent 'poisoned' errors mask it.","Prefer parking_lot::Mutex when poisoning carries no useful signal."],"tags":["mutex","poisoned-lock","concurrency","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}