Skip to content

Commit 3396458

Browse files
committed
fix: stabilize local meta port allocation
1 parent 9c860a7 commit 3396458

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/meta/store/src/local.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,22 @@ impl LocalMetaService {
233233
}
234234

235235
fn next_port() -> u16 {
236-
let base = get_machine_unique_base_port();
237-
let sequence = GlobalSequence::next() as u16;
238-
239-
let port_offset = sequence % 10_000;
240-
let candidate_port = base.saturating_add(port_offset).max(19_000);
241-
242-
if is_port_available(candidate_port) {
243-
return candidate_port;
244-
}
245-
246236
match find_available_port() {
247237
Ok(port) => {
248-
warn!("Calculated port {candidate_port} not available, using {port} instead");
249238
port
250239
}
251240
Err(_) => {
252-
warn!("No available ports found, returning calculated port {candidate_port}");
241+
let base = get_machine_unique_base_port();
242+
let sequence = GlobalSequence::next() as u16;
243+
244+
let port_offset = sequence % 10_000;
245+
let candidate_port = base.saturating_add(port_offset).max(19_000);
246+
247+
if is_port_available(candidate_port) {
248+
return candidate_port;
249+
}
250+
251+
warn!("Failed to find available port, returning fallback port {candidate_port}");
253252
candidate_port
254253
}
255254
}

0 commit comments

Comments
 (0)