gfx-rs/wgpu · error

Failed to open lock observation file (does the dir exist?)

Error message

Failed to open lock observation file (does the dir exist?)

What it means

Panic in the lock-observation machinery's acquire: opening the log file under WGPU_CORE_LOCK_OBSERVE_DIR failed, typically because the directory does not exist or is not writable. The faulty input is the environment-provided observation directory.

Source

Thrown at wgpu-core/src/lock/observing.rs:262

/// Check and record the acquisition of a lock with `new_rank`.
///
/// Log the acquisition of a lock with `new_rank`, and
/// update the per-thread state accordingly.
///
/// Return the `Option<HeldLock>` state that must be restored when this lock is
/// released.
fn acquire(new_rank: LockRank, location: &'static Location<'static>) -> Option<HeldLock> {
    LOCK_STATE.with_borrow_mut(|state| match *state {
        ThreadState::Disabled => None,
        ThreadState::Initial => {
            let Ok(dir) = std::env::var("WGPU_CORE_LOCK_OBSERVE_DIR") else {
                *state = ThreadState::Disabled;
                return None;
            };

            // Create the observation log file.
            let mut log = ObservationLog::create(dir)
                .expect("Failed to open lock observation file (does the dir exist?)");

            // Log the full set of lock ranks, so that the analysis can even see
            // locks that are only acquired in isolation.
            for rank in LockRankSet::all().iter() {
                log.write_rank(rank);
            }

            // Update our state to reflect that we are logging acquisitions, and
            // that we have acquired this lock.
            *state = ThreadState::Enabled {
                held_lock: Some(HeldLock {
                    rank: new_rank,
                    location,
                }),
                log,
            };

            // Since this is the first acquisition on this thread, we know that

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Create the directory pointed to by WGPU_CORE_LOCK_OBSERVE_DIR before starting the program
  2. Unset the variable if lock observation is not intended
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at wgpu-core/src/lock/observing.rs:262 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/9b5e8dbb9c15d2c2. Report an issue: GitHub.