workaround for failure to bind tcp/quic listeners, improved?
This commit is contained in:
parent
9d6fdb3e98
commit
c027f4456d
3 changed files with 48 additions and 30 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// use super::proxy_handler::handle_request;
|
||||
use super::Backends;
|
||||
use crate::{constants::GET_LISTENER_RETRY_TIMEOUT_SEC, error::*, globals::Globals, log::*};
|
||||
use crate::{constants::*, error::*, globals::Globals, log::*};
|
||||
use hyper::{
|
||||
client::connect::Connect, server::conn::Http, service::service_fn, Body, Client, Request,
|
||||
};
|
||||
|
|
@ -78,20 +78,21 @@ 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;
|
||||
}
|
||||
pub(super) async fn try_bind_tcp_listener(&self) -> Result<TcpListener> {
|
||||
let mut cnt = 0;
|
||||
while cnt < GET_LISTENER_RETRY_MAX_CNT {
|
||||
if let Ok(listener) = TcpListener::bind(&self.listening_on).await {
|
||||
return Ok(listener);
|
||||
}
|
||||
};
|
||||
tokio::time::timeout(
|
||||
tokio::time::Duration::from_secs(GET_LISTENER_RETRY_TIMEOUT_SEC),
|
||||
fut,
|
||||
)
|
||||
.await
|
||||
.map_err(|_e| anyhow!("Failed to get listener"))
|
||||
cnt += 1;
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(
|
||||
GET_LISTENER_RETRY_WAITING_MSEC,
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
||||
error!("Failed to get tcp listener: {}", self.listening_on);
|
||||
Err(anyhow!("Failed to get tcp listener: {}", self.listening_on))
|
||||
}
|
||||
|
||||
async fn start_without_tls(self, server: Http<LocalExecutor>) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue