workaround for failure to bind tcp/quic listeners
This commit is contained in:
parent
3fc796303a
commit
1c4e450f1d
4 changed files with 51 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// use super::proxy_handler::handle_request;
|
||||
use super::Backends;
|
||||
use crate::{error::*, globals::Globals, log::*};
|
||||
use crate::{constants::GET_LISTENER_RETRY_TIMEOUT_SEC, error::*, globals::Globals, log::*};
|
||||
use hyper::{
|
||||
client::connect::Connect, server::conn::Http, service::service_fn, Body, Client, Request,
|
||||
};
|
||||
|
|
@ -77,9 +77,27 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
// Work around to forcibly get tcp listener for "address already in use"
|
||||
async fn try_bind_tcp_listener(&self) -> Result<TcpListener> {
|
||||
let fut = async {
|
||||
loop {
|
||||
if let Ok(listener) = TcpListener::bind(&self.listening_on).await {
|
||||
break listener;
|
||||
}
|
||||
}
|
||||
};
|
||||
tokio::time::timeout(
|
||||
tokio::time::Duration::from_secs(GET_LISTENER_RETRY_TIMEOUT_SEC),
|
||||
fut,
|
||||
)
|
||||
.await
|
||||
.map_err(|_e| anyhow!("Failed to get listener"))
|
||||
}
|
||||
|
||||
async fn start_without_tls(self, server: Http<LocalExecutor>) -> Result<()> {
|
||||
let listener_service = async {
|
||||
let tcp_listener = TcpListener::bind(&self.listening_on).await?;
|
||||
// let tcp_listener = TcpListener::bind(&self.listening_on).await?;
|
||||
let tcp_listener = self.try_bind_tcp_listener().await?;
|
||||
info!(
|
||||
"Start TCP proxy serving with HTTP request for configured host names: {:?}",
|
||||
tcp_listener.local_addr()?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue