firecracker-microvm/firecracker · error
poisoned lock
Error message
poisoned lock
What it means
Error "poisoned lock" thrown in firecracker-microvm/firecracker.
Source
Thrown at src/vmm/src/logger/metrics.rs:153
/// Upon success, the function will return `True` (if metrics system was initialized and metrics
/// were successfully written to disk) or `False` (if metrics system was not yet initialized).
///
/// This function is usually supposed to be called only from a single thread and
/// is not meant to be used in a multithreaded scenario. The reason
/// `metrics_buf` is enclosed in a `Mutex` is that `lazy_static` enforces
/// thread-safety on all its members.
/// The only exception is for signal handlers that result in process exit, which may be run on
/// any thread. To prevent the race condition present in the serialisation step of
/// SharedIncMetrics, deadly signals use SharedStoreMetrics instead (which have a thread-safe
/// serialise implementation).
/// The only known caveat is that other metrics may not be properly written before exiting from
/// a signal handler. We make this compromise since the process will be killed anyway and the
/// important metric in this case is the signal one.
/// The alternative is to hold a Mutex over the entire function call, but this increases the
/// known deadlock potential.
pub fn write(&self) -> Result<bool, MetricsError> {
if let Some(lock) = self.metrics_buf.get() {
let mut writer = lock.lock().expect("poisoned lock");
serde_json::to_writer(writer.by_ref(), &self.app_metrics)
.map_err(|err| MetricsError::Serde(err.to_string()))?;
writer.write_all(b"\n").map_err(MetricsError::Write)?;
Ok(true)
} else {
// If the metrics are not initialized, no error is thrown but we do let the user know
// that metrics were not written.
Ok(false)
}
}
}
impl<T: Serialize + Debug, M: Write + Send + Debug> Deref for Metrics<T, M> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.app_metrics
}View on GitHub (pinned to 0a745def42)
Solutions
- Find and fix the earlier panic that poisoned the metrics lock.
- Recover with into_inner() only if the metrics state is provably consistent after the panic.
When it happens
Trigger: Thrown at src/vmm/src/logger/metrics.rs:153 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of firecracker-microvm/firecracker@0a745def42 (2026-08-19).
Data as JSON: /api/errors/fdcdc85522bb9d31.
Report an issue: GitHub.