fix(stub): Prevent infinite reconnect loop causing port exhaustion

- Added a break statement when send_task exits (STDIN closed).
- Increased reconnect delay from 50ms to 1 second to prevent ephemeral port exhaustion when the server repeatedly drops connections.
This commit is contained in:
Riz Ashraf committed 2026-09-20 23:02:55 +01:00
1 parent cb8447224f
commit acf5ea8ebe
1 file changed
+7 -4
+7 -4
View File
@@ -117,20 +117,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}); });
tokio::select! { tokio::select! {
_ = shutdown_rx.recv() => { tokio::time::sleep(tokio::time::Duration::from_millis(50)).await; _ = shutdown_rx.recv() => {
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
tracing::info!("Shutdown received while connected"); tracing::info!("Shutdown received while connected");
break;
} }
_ = &mut send_task => { _ = &mut send_task => {
tracing::error!("Send task exited"); tracing::error!("Send task exited");
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await; recv_task.abort(); tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
recv_task.abort();
break;
} }
_ = &mut recv_task => { _ = &mut recv_task => {
tracing::error!("Recv task exited"); tracing::error!("Recv task exited");
send_task.abort(); send_task.abort();
} }
} }
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await; tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
} }
Err(e) => { Err(e) => {
tracing::error!("Failed to connect via WSS: {}", e); tracing::error!("Failed to connect via WSS: {}", e);