From 421a5a230cab6d188e7f6a5d8b92b8f9a5838be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Wed, 1 May 2024 15:00:35 +0200 Subject: [PATCH] feat(restriction): Avoid re-creating a config reload notifier each time --- src/restrictions/config_reloader.rs | 2 +- src/tunnel/server.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/restrictions/config_reloader.rs b/src/restrictions/config_reloader.rs index 95ca2b6..beae0cb 100644 --- a/src/restrictions/config_reloader.rs +++ b/src/restrictions/config_reloader.rs @@ -94,7 +94,7 @@ impl RestrictionsRulesReloader { &self.restrictions } - pub fn wait_for_reload(&self) -> Notified { + pub fn reload_notifier(&self) -> Notified { match &self.state { Static(st) => st.notified(), Config(st) => st.should_reload_config.notified(), diff --git a/src/tunnel/server.rs b/src/tunnel/server.rs index 28424e1..d77742a 100644 --- a/src/tunnel/server.rs +++ b/src/tunnel/server.rs @@ -728,12 +728,16 @@ pub async fn run_server(server_config: Arc, restrictions: Restri // Bind server and run forever to serve incoming connections. let mut restrictions = RestrictionsRulesReloader::new(restrictions, server_config.restriction_config.clone())?; let listener = TcpListener::bind(&server_config.bind).await?; + let mut await_config_reload = Box::pin(restrictions.reload_notifier()); + loop { let cnx = select! { biased; - _ = restrictions.wait_for_reload() => { + _ = &mut await_config_reload => { + drop(await_config_reload); restrictions.reload_restrictions_config(); + await_config_reload = Box::pin(restrictions.reload_notifier()); continue; },