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
- Only call `stop()` after a confirmed successful `start()`
- Track profiling state in your own code (bool/guard) and make stop idempotent
- 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
- Track profiling state yourself and only stop when a start succeeded
- Make shutdown/cleanup paths idempotent with respect to stop()
- Never call stop() from destructors that may run after state reset
- Guard start/stop pairs in a single RAII type
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
- profiler already started
- profiler failed to start
- We explicitly do not provide canonicalization API, as that i
- bad kind {other}
- bad spacing {other}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/a52a0867fd2bfb1b.
Report an issue: GitHub.