Skip to content

Commit d9a1f97

Browse files
committed
test: Log which process holds a port on InvalidSocketAddress
Run lsof to identify what is using the port when node.start() fails with a binding error. This helps distinguish between collisions with electrsd/bitcoind, other test processes, or TIME_WAIT leftovers. AI tools were used in preparing this commit.
1 parent 0c83072 commit d9a1f97

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/common/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,29 @@ pub(crate) fn setup_node(chain_source: &TestChainSource, config: TestConfig) ->
514514
return node;
515515
},
516516
Err(NodeError::InvalidSocketAddress) => {
517+
if let Some(ref addrs) = node_config.listening_addresses {
518+
for addr in addrs {
519+
if let SocketAddress::TcpIpV4 { port, .. }
520+
| SocketAddress::TcpIpV6 { port, .. } = addr
521+
{
522+
let output = std::process::Command::new("lsof")
523+
.args(["-i", &format!(":{}", port), "-P", "-n"])
524+
.output();
525+
match output {
526+
Ok(o) if !o.stdout.is_empty() => {
527+
eprintln!(
528+
"Port {} is in use:\n{}",
529+
port,
530+
String::from_utf8_lossy(&o.stdout)
531+
);
532+
},
533+
_ => {
534+
eprintln!("Port {} appears unavailable (no lsof info)", port);
535+
},
536+
}
537+
}
538+
}
539+
}
517540
eprintln!("node.start() failed with InvalidSocketAddress, retrying...");
518541
continue;
519542
},

0 commit comments

Comments
 (0)