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.
for _ in 0..100 {
// This will generally fail immediately when the port is still closed.
let josh_ready = net::TcpStream::connect_timeout( let josh_ready = net::TcpStream::connect_timeout(
&net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)), &net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)),
Duration::from_secs(1), Duration::from_millis(1),
) );
.context("failed to connect to josh-proxy")?; if josh_ready.is_ok() {
drop(josh_ready); return Ok(Josh(josh));
}
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<()> {