fix: auto-reconnect to server after conect failure instead of exiting

This commit is contained in:
Σrebe - Romain GERARD 2024-03-04 17:06:00 +01:00
parent f4f60efd47
commit 84d753fa25
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4

View file

@ -109,16 +109,30 @@ where
// Correctly configure tunnel cfg // Correctly configure tunnel cfg
let (ws_rx, ws_tx, response) = match client_cfg.remote_addr.scheme() { let (ws_rx, ws_tx, response) = match client_cfg.remote_addr.scheme() {
TransportScheme::Ws | TransportScheme::Wss => { TransportScheme::Ws | TransportScheme::Wss => {
tunnel::transport::websocket::connect(request_id, &client_cfg, &remote_addr) match tunnel::transport::websocket::connect(request_id, &client_cfg, &remote_addr)
.instrument(span.clone()) .instrument(span.clone())
.await .await
.map(|(r, w, response)| (TunnelReader::Websocket(r), TunnelWriter::Websocket(w), response))? {
Ok((r, w, response)) => (TunnelReader::Websocket(r), TunnelWriter::Websocket(w), response),
Err(err) => {
error!("Retrying in 1sec, cannot connect to remote server: {:?}", err);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
continue;
}
}
} }
TransportScheme::Http | TransportScheme::Https => { TransportScheme::Http | TransportScheme::Https => {
tunnel::transport::http2::connect(request_id, &client_cfg, &remote_addr) match tunnel::transport::http2::connect(request_id, &client_cfg, &remote_addr)
.instrument(span.clone()) .instrument(span.clone())
.await .await
.map(|(r, w, response)| (TunnelReader::Http2(r), TunnelWriter::Http2(w), response))? {
Ok((r, w, response)) => (TunnelReader::Http2(r), TunnelWriter::Http2(w), response),
Err(err) => {
error!("Retrying in 1sec, cannot connect to remote server: {:?}", err);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
continue;
}
}
} }
}; };