aboutsummaryrefslogtreecommitdiff
path: root/src/proxy_config.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-24 19:28:18 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-24 19:28:18 +0100
commit5e5299a6d0addc6498be12a24451860b9e4c3445 (patch)
treeee09ba8e40ae0e14af3dbe2ec4e576a6f0b4aea0 /src/proxy_config.rs
parentd7511c683d47cdc6eb2d19f4276b359b1c6841f6 (diff)
downloadtricot-5e5299a6d0addc6498be12a24451860b9e4c3445.tar.gz
tricot-5e5299a6d0addc6498be12a24451860b9e4c3445.zip
Add graceful shutdown and memory tracing
Diffstat (limited to 'src/proxy_config.rs')
-rw-r--r--src/proxy_config.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/proxy_config.rs b/src/proxy_config.rs
index 4add98c..e380885 100644
--- a/src/proxy_config.rs
+++ b/src/proxy_config.rs
@@ -9,7 +9,7 @@ use futures::future::BoxFuture;
use futures::stream::{FuturesUnordered, StreamExt};
use log::*;
-use tokio::{sync::watch, time::sleep};
+use tokio::{select, sync::watch, time::sleep};
use crate::consul::*;
@@ -231,7 +231,10 @@ struct NodeWatchState {
retries: u32,
}
-pub fn spawn_proxy_config_task(consul: Consul) -> watch::Receiver<Arc<ProxyConfig>> {
+pub fn spawn_proxy_config_task(
+ consul: Consul,
+ mut must_exit: watch::Receiver<bool>,
+) -> watch::Receiver<Arc<ProxyConfig>> {
let (tx, rx) = watch::channel(Arc::new(ProxyConfig {
entries: Vec::new(),
}));
@@ -244,8 +247,13 @@ pub fn spawn_proxy_config_task(consul: Consul) -> watch::Receiver<Arc<ProxyConfi
let mut node_site = HashMap::new();
- loop {
- match consul.list_nodes().await {
+ while !*must_exit.borrow() {
+ let list_nodes = select! {
+ ln = consul.list_nodes() => ln,
+ _ = must_exit.changed() => continue,
+ };
+
+ match list_nodes {
Ok(consul_nodes) => {
info!("Watched consul nodes: {:?}", consul_nodes);
for consul_node in consul_nodes {
@@ -271,7 +279,12 @@ pub fn spawn_proxy_config_task(consul: Consul) -> watch::Receiver<Arc<ProxyConfi
}
}
- let (node, res): (String, Result<_>) = match watches.next().await {
+ let next_watch = select! {
+ nw = watches.next() => nw,
+ _ = must_exit.changed() => continue,
+ };
+
+ let (node, res): (String, Result<_>) = match next_watch {
Some(v) => v,
None => {
warn!("No nodes currently watched in proxy_config.rs");