openai/codex · error · anyhow::Error

CreateMutexW failed

Error message

CreateMutexW failed: {}

What it means

CreateMutexW for the named read-ACL mutex returned a null handle, so the setup run cannot acquire the cross-process lock that serializes read-ACL refresh work. The mutex creation call already passes an initial-ownership flag, so failure here means Windows could not create/open the named kernel object at all.

Solutions

  1. Check the GetLastError code reported in the message to identify the kernel object creation failure
  2. Ensure the process has rights to create the named mutex in its session; running elevated typically resolves access-denied creation failures
  3. Terminate stale codex sandbox processes that may hold conflicting object state, then retry setup
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win/read_acl_mutex.rs:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/1da771011057ceee. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win/read_acl_mutex.rs:49

    let handle = unsafe { OpenMutexW(MUTEX_ALL_ACCESS, 0, name.as_ptr()) };
    if handle == 0 {
        let err = unsafe { GetLastError() };
        if err == ERROR_FILE_NOT_FOUND {
            return Ok(false);
        }
        return Err(anyhow::anyhow!("OpenMutexW failed: {err}"));
    }
    unsafe {
        CloseHandle(handle);
    }
    Ok(true)
}

pub(super) fn acquire_read_acl_mutex() -> Result<Option<ReadAclMutexGuard>> {
    let name = to_wide(OsStr::new(READ_ACL_MUTEX_NAME));
    let handle = unsafe { CreateMutexW(std::ptr::null_mut(), 1, name.as_ptr()) };
    if handle == 0 {
        return Err(anyhow::anyhow!("CreateMutexW failed: {}", unsafe {
            GetLastError()
        }));
    }
    let err = unsafe { GetLastError() };
    if err == ERROR_ALREADY_EXISTS {
        unsafe {
            CloseHandle(handle);
        }
        return Ok(None);
    }
    Ok(Some(ReadAclMutexGuard { handle }))
}

View on GitHub (pinned to 339751715c)