From 45174ebe7dc10f9a305d1579343d95d262e24fa7 Mon Sep 17 00:00:00 2001 From: syoul Date: Sun, 26 Apr 2026 00:06:50 +0200 Subject: [PATCH] fix(sidecar): pin metrics-api-address to ephemeral port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even with --api-addr set, mycelium also opens an internal JSON-RPC endpoint on 127.0.0.1:8990 by default (visible in --debug as \"Starting JSON-RPC server listen_addr=127.0.0.1:8990\"). When a previous run left an orphan mycelium running as root — which we can't SIGKILL from a user-level Child::kill_on_drop — the new instance fails to bind 8990 and exits ~10s after startup, with no sidecar://exited event because the kill never landed. Pin --metrics-api-address to a fresh ephemeral port alongside the other three. Known limitation: stopping the daemon still doesn't reliably kill the root child; the user has to `sudo pkill mycelium` between runs. Will be addressed by an elevated-shutdown hook. --- src-tauri/src/sidecar.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/sidecar.rs b/src-tauri/src/sidecar.rs index 89704a9..8d93756 100644 --- a/src-tauri/src/sidecar.rs +++ b/src-tauri/src/sidecar.rs @@ -110,6 +110,12 @@ impl SidecarHandle { let api_port = pick_port()?; let tcp_port = pick_port_skip(&[api_port])?; let quic_port = pick_port_skip(&[api_port, tcp_port])?; + // mycelium also opens an internal JSON-RPC / metrics endpoint on + // 127.0.0.1:8990 by default; if 8990 is already taken (e.g. by an + // orphan from a previous run we couldn't SIGKILL because it ran as + // root) the new instance dies a few seconds after start. Pin this + // to a fresh ephemeral port too. + let metrics_port = pick_port_skip(&[api_port, tcp_port, quic_port])?; let data_dir = app .path() @@ -126,6 +132,8 @@ impl SidecarHandle { tcp_port.to_string(), "--quic-listen-port".to_string(), quic_port.to_string(), + "--metrics-api-address".to_string(), + format!("127.0.0.1:{metrics_port}"), "--key-file".to_string(), key_path.display().to_string(), ]; @@ -149,7 +157,7 @@ impl SidecarHandle { info!( ?bin, - api_port, tcp_port, quic_port, + api_port, tcp_port, quic_port, metrics_port, "spawning mycelium sidecar via pkexec" );