Skip to content

Commit

Permalink
feat(restriction): Avoid re-creating a config reload notifier each time
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed May 1, 2024
1 parent 862d1dc commit 421a5a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/restrictions/config_reloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion src/tunnel/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,16 @@ pub async fn run_server(server_config: Arc<WsServerConfig>, 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;
},

Expand Down

0 comments on commit 421a5a2

Please sign in to comment.