From a552e695f74d0071acc304bf5fe5a8d0262d43de Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 4 Aug 2023 05:17:20 +0200 Subject: [PATCH] fix(relay): wait for channel binding in smoke test script (#1853) `webrtc-rs` has a race condition where `send_to` does not actually await the channel binding, thus attempting to send something through the channel from the other end my fail because we receive the bytes from the relay before the library registers that there is an active channel. This should hopefully fix the flakiness of the smoke test script. --- rust/relay/examples/client.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/relay/examples/client.rs b/rust/relay/examples/client.rs index cf9ccf26b..8643f38dc 100644 --- a/rust/relay/examples/client.rs +++ b/rust/relay/examples/client.rs @@ -2,6 +2,7 @@ use anyhow::Result; use redis::AsyncCommands; use std::net::SocketAddr; use std::sync::Arc; +use std::time::Duration; use tokio::net::UdpSocket; use webrtc::turn::client::*; use webrtc::turn::Error; @@ -33,6 +34,10 @@ async fn main() -> Result<()> { // Instead, it will implicitly create one when trying to send data to a remote. relay_conn.send_to(b"HOLEPUNCH", gateway_addr).await?; + // `webrtc-ts` does not block on the creation of the channel binding. + // Wait for some amount of time here to avoid race conditions. + tokio::time::sleep(Duration::from_millis(10)).await; + println!("Created channel to gateway"); // Now that our relay connection is active, share the address with the gateway.