From 06b34eba97ef7f24474d69a16b24c012d945c3d8 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 14 Oct 2024 14:58:59 -0300 Subject: [PATCH] Fix is_port_in_use --- .../zkstack/src/commands/dev/commands/status.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/commands/status.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/status.rs index 1ab57e2513a5..153b5cbd18cd 100644 --- a/zkstack_cli/crates/zkstack/src/commands/dev/commands/status.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/status.rs @@ -172,10 +172,7 @@ fn print_status(health_check_url: String) -> anyhow::Result<()> { } fn is_port_in_use(port: u16) -> bool { - match TcpListener::bind(("127.0.0.1", port)) { - Ok(_listener) => false, - Err(_e) => true, - } + TcpListener::bind(("0.0.0.0", port)).is_err() || TcpListener::bind(("127.0.0.1", port)).is_err() } fn print_ports(shell: &Shell) -> anyhow::Result<()> { @@ -195,8 +192,8 @@ fn print_ports(shell: &Shell) -> anyhow::Result<()> { }; port_info_lines.push_str(&format!( - " - {} > {}{}\n", - port_info.port, port_info.description, in_use_tag + " - {}{} > {}\n", + port_info.port, in_use_tag, port_info.description )); } @@ -210,7 +207,7 @@ fn print_ports(shell: &Shell) -> anyhow::Result<()> { .then_with(|| a.cmp(b)) }); - let mut components_info = String::from("Used ports:\n"); + let mut components_info = String::new(); for chunk in all_port_lines.chunks(2) { components_info.push_str(&bordered_boxes(&chunk[0], chunk.get(1))); }