fix(sidecar): pin metrics-api-address to ephemeral port
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.
This commit is contained in:
@@ -110,6 +110,12 @@ impl SidecarHandle {
|
|||||||
let api_port = pick_port()?;
|
let api_port = pick_port()?;
|
||||||
let tcp_port = pick_port_skip(&[api_port])?;
|
let tcp_port = pick_port_skip(&[api_port])?;
|
||||||
let quic_port = pick_port_skip(&[api_port, tcp_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
|
let data_dir = app
|
||||||
.path()
|
.path()
|
||||||
@@ -126,6 +132,8 @@ impl SidecarHandle {
|
|||||||
tcp_port.to_string(),
|
tcp_port.to_string(),
|
||||||
"--quic-listen-port".to_string(),
|
"--quic-listen-port".to_string(),
|
||||||
quic_port.to_string(),
|
quic_port.to_string(),
|
||||||
|
"--metrics-api-address".to_string(),
|
||||||
|
format!("127.0.0.1:{metrics_port}"),
|
||||||
"--key-file".to_string(),
|
"--key-file".to_string(),
|
||||||
key_path.display().to_string(),
|
key_path.display().to_string(),
|
||||||
];
|
];
|
||||||
@@ -149,7 +157,7 @@ impl SidecarHandle {
|
|||||||
|
|
||||||
info!(
|
info!(
|
||||||
?bin,
|
?bin,
|
||||||
api_port, tcp_port, quic_port,
|
api_port, tcp_port, quic_port, metrics_port,
|
||||||
"spawning mycelium sidecar via pkexec"
|
"spawning mycelium sidecar via pkexec"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user