Skip to content

Commit e17e9fe

Browse files
committed
fix: keep the test Client alive past the connect() success signal
Found the actual root cause of the remaining CI flake: `client` was constructed and dropped inside the innermost closure, so it closed its TCP connection immediately after connect() returned Ok -- before (or racing) the setup_tx notification the driver loop was waiting on. If the driver loop's next server.poll() ran before it saw that notification, it could observe and process the resulting disconnect, evicting the connection from server.connections before the test ever got to assert on it (reproduced in CI as `left: 0, right: 1` in ~1.8s, i.e. not a timeout). Move `client` out to the thread closure's own scope so it stays connected through the success signal and the driver loop's final break -- no poll() call happens after that point, so the connection can no longer be raced away. Verified stable over 10 runs locally, both with default and --test-threads=1 parallelism (the mode the failing CI job used). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ZRH22k5s8VSoSJgUXa2wd
1 parent 76750b5 commit e17e9fe

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

tests/server_client_loopback.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,19 @@ fn connect_and_wait(
380380
// other, older tests in this file were written against.
381381
let client_timeout = Duration::from_secs(20);
382382
let client_thread = thread::spawn(move || {
383-
let result = (|| -> std::result::Result<(), librtmp2::types::ErrorCode> {
384-
let mut client = Client::new();
385-
client.set_connect_timeout(client_timeout);
386-
if with_reconnect_cb {
387-
client.on_reconnect_request_cb = Some(noop_reconnect_request);
388-
}
389-
client.connect(&url)?;
390-
Ok(())
391-
})();
383+
// `client` must stay alive (and its transport connected) past the
384+
// point where the main thread observes success and inspects
385+
// `server.connections` -- dropping it right after `connect()`
386+
// returns closes the TCP connection immediately, racing the
387+
// server's own bookkeeping and intermittently making the
388+
// connection vanish from `server.connections` before the caller
389+
// ever gets to look at it.
390+
let mut client = Client::new();
391+
client.set_connect_timeout(client_timeout);
392+
if with_reconnect_cb {
393+
client.on_reconnect_request_cb = Some(noop_reconnect_request);
394+
}
395+
let result = client.connect(&url);
392396
let _ = setup_tx.send(result.is_ok());
393397
result.unwrap();
394398
thread::sleep(Duration::from_millis(200));

0 commit comments

Comments
 (0)