rust-lang/rust-analyzer · error

profiler is not started

Error message

profiler is not started

What it means

`stop` transitions the profiler state ON -> PENDING before calling `ProfilerStop`. If the profiler is not currently running (state is not ON), the transition fails and `stop` panics with 'profiler is not started', protecting against stopping a non-existent profile session.

Source

Thrown at crates/profile/src/google_cpu_profiler.rs:40

    static STATE: AtomicUsize = AtomicUsize::new(OFF);

    STATE.compare_exchange(current, new, Ordering::SeqCst, Ordering::SeqCst).is_ok()
}

pub(crate) fn start(path: &Path) {
    if !transition(OFF, PENDING) {
        panic!("profiler already started");
    }
    let path = CString::new(path.display().to_string()).unwrap();
    if unsafe { ProfilerStart(path.as_ptr()) } == 0 {
        panic!("profiler failed to start")
    }
    assert!(transition(PENDING, ON));
}

pub(crate) fn stop() {
    if !transition(ON, PENDING) {
        panic!("profiler is not started")
    }
    unsafe { ProfilerStop() };
    assert!(transition(PENDING, OFF));
}

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Only call `stop()` after a confirmed successful `start()`
  2. Track profiling state in your own code (bool/guard) and make stop idempotent
  3. Fix duplicated cleanup paths that invoke stop more than once

Example fix

// before
profiler::stop(); // unconditional, may panic
// after
if profiling {
    profiler::stop();
    profiling = false;
}
Defensive patterns

Strategy: try-catch

Validate before calling

static PROFILING: AtomicBool = AtomicBool::new(false);
fn can_stop() -> bool { PROFILING.load(Ordering::SeqCst) }

Try / catch

std::panic::catch_unwind(|| profiler::stop())
    .err()
    .map(|_| eprintln!("profiler was not running; ignoring stop"));

Prevention

When it happens

Trigger: Calling `profile::stop()` without a prior successful `start()`; calling `stop()` twice; calling `stop()` while a `start()` is still initializing (PENDING state).

Common situations: Cleanup/shutdown code that unconditionally calls stop; a previous start that panicked left nothing to stop; lifecycle bugs where stop runs in a destructor after state was already reset.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/a52a0867fd2bfb1b. Report an issue: GitHub.