josh-proxy: fix wait-for-josh logic

This commit is contained in:
Ralf Jung 2024-08-12 10:07:53 +02:00
parent 3456432db1
commit 2b83935192

View File

@ -137,15 +137,20 @@ fn drop(&mut self) {
} }
} }
// Wait until the port is open. // Wait until the port is open. We try every 10ms until 1s passed.
let josh_ready = net::TcpStream::connect_timeout( for _ in 0..100 {
&net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)), // This will generally fail immediately when the port is still closed.
Duration::from_secs(1), let josh_ready = net::TcpStream::connect_timeout(
) &net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)),
.context("failed to connect to josh-proxy")?; Duration::from_millis(1),
drop(josh_ready); );
if josh_ready.is_ok() {
Ok(Josh(josh)) return Ok(Josh(josh));
}
// Not ready yet.
std::thread::sleep(Duration::from_millis(10));
}
bail!("Even after waiting for 1s, josh-proxy is still not available.")
} }
pub fn exec(self) -> Result<()> { pub fn exec(self) -> Result<()> {