Skip to content

Commit 2b83935

Browse files
committed
josh-proxy: fix wait-for-josh logic
1 parent 3456432 commit 2b83935

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/tools/miri/miri-script/src/commands.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,20 @@ impl Command {
137137
}
138138
}
139139

140-
// Wait until the port is open.
141-
let josh_ready = net::TcpStream::connect_timeout(
142-
&net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)),
143-
Duration::from_secs(1),
144-
)
145-
.context("failed to connect to josh-proxy")?;
146-
drop(josh_ready);
147-
148-
Ok(Josh(josh))
140+
// Wait until the port is open. We try every 10ms until 1s passed.
141+
for _ in 0..100 {
142+
// This will generally fail immediately when the port is still closed.
143+
let josh_ready = net::TcpStream::connect_timeout(
144+
&net::SocketAddr::from(([127, 0, 0, 1], JOSH_PORT)),
145+
Duration::from_millis(1),
146+
);
147+
if josh_ready.is_ok() {
148+
return Ok(Josh(josh));
149+
}
150+
// Not ready yet.
151+
std::thread::sleep(Duration::from_millis(10));
152+
}
153+
bail!("Even after waiting for 1s, josh-proxy is still not available.")
149154
}
150155

151156
pub fn exec(self) -> Result<()> {

0 commit comments

Comments
 (0)