{"record":{"id":"bbdd683b5c6219f9","repo":"zed-industries/zed","slug":"unable-to-create-instance-mutex","errorCode":null,"errorMessage":"Unable to create instance mutex.","messagePattern":"Unable to create instance mutex\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zed/src/zed/windows_only_instance.rs","lineNumber":36,"sourceCode":"                PIPE_TYPE_MESSAGE, PIPE_WAIT,\n            },\n            Threading::CreateMutexW,\n        },\n    },\n    core::HSTRING,\n};\n\nuse crate::{Args, OpenListener, RawOpenRequest};\n\n#[inline]\nfn is_first_instance() -> bool {\n    unsafe {\n        CreateMutexW(\n            None,\n            false,\n            &HSTRING::from(format!(\"{}-Instance-Mutex\", app_identifier())),\n        )\n        .expect(\"Unable to create instance mutex.\")\n    };\n    unsafe { GetLastError() != ERROR_ALREADY_EXISTS }\n}\n\npub fn handle_single_instance(opener: OpenListener, args: &Args) -> bool {\n    let is_first_instance = is_first_instance();\n    if is_first_instance {\n        // We are the first instance, listen for messages sent from other instances\n        std::thread::Builder::new()\n            .name(\"EnsureSingleton\".to_owned())\n            .spawn(move || {\n                with_pipe(&|url| {\n                    opener.open(RawOpenRequest {\n                        urls: vec![url],\n                        ..Default::default()\n                    })\n                })\n            })","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/zed/src/zed/windows_only_instance.rs#L18-L54","documentation":"is_first_instance panics when CreateMutexW fails to create the Windows instance mutex — an OS-level error (permissions, handle exhaustion) prevents the single-instance check from even being evaluated.","triggerScenarios":"Thrown at crates/zed/src/zed/windows_only_instance.rs:36 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the Windows error code via GetLastError and log it","Treat mutex creation failure as 'first instance' with a warning instead of crashing","Verify app_identifier() produces a valid mutex name"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}