{"record":{"id":"6092e398764980b3","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-6092e3","errorCode":null,"errorMessage":"微信连接运行锁已损坏","messagePattern":"微信连接运行锁已损坏","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/codex-plus-manager/src-tauri/src/commands.rs","lineNumber":1486,"sourceCode":"    let config = codex_plus_core::connect::WeixinConnectConfig {\n        base_url: settings.weixin_connect_base_url,\n        token: settings.weixin_connect_token,\n        account_id: settings.weixin_connect_account_id,\n        allow_from: settings.weixin_connect_allow_from,\n        route_tag: settings.weixin_connect_route_tag,\n        work_dir: settings.weixin_connect_work_dir,\n        model: settings.weixin_connect_model,\n        sandbox: settings.weixin_connect_sandbox,\n        codex_path: settings.weixin_connect_codex_path,\n    }\n    .normalized();\n    if config.token.is_empty() {\n        anyhow::bail!(\"微信连接 token 为空\");\n    }\n    let stop = Arc::new(AtomicBool::new(false));\n    let mut runtime = weixin_runtime()\n        .lock()\n        .map_err(|_| anyhow::anyhow!(\"微信连接运行锁已损坏\"))?;\n    if runtime.is_some() {\n        anyhow::bail!(\"微信连接已在运行或正在停止\");\n    }\n    let codex_path = codex_plus_core::connect::WeixinCodexPath::new(&config.codex_path);\n    *runtime = Some(WeixinRuntime {\n        stop: Arc::clone(&stop),\n        codex_path: codex_path.clone(),\n    });\n    drop(runtime);\n    let status = weixin_status();\n    if let Ok(mut current) = status.lock() {\n        current.state = \"starting\".to_string();\n        current.message = \"正在启动微信连接...\".to_string();\n        current.account_id = config.account_id.clone();\n        current.has_token = true;\n    }\n    let task_status = Arc::clone(&status);\n    let task_stop = Arc::clone(&stop);","sourceCodeStart":1468,"sourceCodeEnd":1504,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/apps/codex-plus-manager/src-tauri/src/commands.rs#L1468-L1504","documentation":"The WeChat (weixin) connect command stores its running runtime handle behind a global Mutex via weixin_runtime(). Calling .lock() returns Err when the mutex is poisoned — a previous thread panicked while holding the lock — and this error maps that poisoning into a user-facing message meaning the run-state lock is unrecoverable through the normal API.","triggerScenarios":"Calling the weixin connect command after some earlier code path panicked while holding the weixin_runtime() mutex, leaving it poisoned so .lock() returns Err(PoisonError).","commonSituations":"A panic in a prior WeChat connection task (network unwrap, index panic, forced stop path) poisoned the lock; long-running manager process accumulating a poisoned runtime after one bad session; bug in WeixinRuntime drop/stop logic panicking under the lock.","solutions":["Restart the CodexPlusPlus manager process to clear the poisoned mutex","Find and fix the panic that poisoned the lock (check logs from the prior WeChat session)","Replace lock().map_err with lock().unwrap_or_else(|p| p.into_inner()) if the guarded state is safe to recover","Audit stop/cleanup paths in the WeChat runtime to remove panics while the lock is held"],"exampleFix":"// before\nlet mut runtime = weixin_runtime()\n    .lock()\n    .map_err(|_| anyhow::anyhow!(\"微信连接运行锁已损坏\"))?;\n// after\nlet mut runtime = match weixin_runtime().lock() {\n    Ok(guard) => guard,\n    Err(poisoned) => poisoned.into_inner(), // 状态本身可安全恢复时才这样做\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let mut runtime = match weixin_runtime().lock() {\n    Ok(guard) => guard,\n    Err(poisoned) => {\n        log::warn!(\"weixin runtime lock was poisoned; recovering state\");\n        poisoned.into_inner() // 仅当受保护状态可安全恢复时\n    }\n};","preventionTips":["Never panic while holding the weixin_runtime mutex — convert panics into Result errors in the WeChat session code","Use poisoned.into_inner() recovery if the guarded runtime state is always safe to reuse","Check manager logs from the previous WeChat session for the panic that poisoned the lock","Wrap runtime stop/cleanup logic in catch_unwind if third-party code runs under the lock"],"tags":["rust","mutex-poisoned","concurrency","weixin","tauri"],"backgroundTag":"thread-interrupted","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"}