fix(doctor): make generated ids unique per call (#1330)

This commit is contained in:
Chris Tate
2026-05-06 10:48:19 -05:00
committed by GitHub
parent 918d407411
commit 3bb1d43f8b
+8 -3
View File
@@ -2,6 +2,7 @@
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::SystemTime; use std::time::SystemTime;
use serde_json::Value; use serde_json::Value;
@@ -81,15 +82,19 @@ pub(super) fn parse_json_file(path: &Path) -> Result<(), String> {
Ok(()) Ok(())
} }
/// Generate a unique `doctor-<pid>-<micros>` id for JSON command envelopes. /// Generate a unique `doctor-<pid>-<micros>-<sequence>` id for JSON command envelopes.
pub(super) fn new_id() -> String { pub(super) fn new_id() -> String {
static NEXT_ID: AtomicU64 = AtomicU64::new(0);
let sequence = NEXT_ID.fetch_add(1, Ordering::Relaxed);
format!( format!(
"doctor-{}-{}", "doctor-{}-{}-{}",
std::process::id(), std::process::id(),
SystemTime::now() SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH) .duration_since(SystemTime::UNIX_EPOCH)
.map(|d| d.as_micros()) .map(|d| d.as_micros())
.unwrap_or(0) .unwrap_or(0),
sequence
) )
} }