Skip to content

Commit 3bb1d43

Browse files
authored
fix(doctor): make generated ids unique per call (#1330)
1 parent 918d407 commit 3bb1d43

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

cli/src/doctor/helpers.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::fs;
44
use std::path::Path;
5+
use std::sync::atomic::{AtomicU64, Ordering};
56
use std::time::SystemTime;
67

78
use serde_json::Value;
@@ -81,15 +82,19 @@ pub(super) fn parse_json_file(path: &Path) -> Result<(), String> {
8182
Ok(())
8283
}
8384

84-
/// Generate a unique `doctor-<pid>-<micros>` id for JSON command envelopes.
85+
/// Generate a unique `doctor-<pid>-<micros>-<sequence>` id for JSON command envelopes.
8586
pub(super) fn new_id() -> String {
87+
static NEXT_ID: AtomicU64 = AtomicU64::new(0);
88+
let sequence = NEXT_ID.fetch_add(1, Ordering::Relaxed);
89+
8690
format!(
87-
"doctor-{}-{}",
91+
"doctor-{}-{}-{}",
8892
std::process::id(),
8993
SystemTime::now()
9094
.duration_since(SystemTime::UNIX_EPOCH)
9195
.map(|d| d.as_micros())
92-
.unwrap_or(0)
96+
.unwrap_or(0),
97+
sequence
9398
)
9499
}
95100

0 commit comments

Comments
 (0)