fix: change tokio::sync::Notify to tokio_util::sync::CancellationToken

This commit is contained in:
Jun Kurihara 2024-07-26 20:58:00 +09:00
commit 0950fdbd15
No known key found for this signature in database
GPG key ID: D992B3E3DE1DED23
8 changed files with 22 additions and 18 deletions

View file

@ -30,4 +30,5 @@ rustls-acme = { path = "../submodules/rustls-acme/", default-features = false, f
"aws-lc-rs",
] }
tokio = { version = "1.39.1", default-features = false }
tokio-util = { version = "0.7.11", default-features = false }
tokio-stream = { version = "0.1.15", default-features = false }

View file

@ -74,7 +74,7 @@ impl AcmeManager {
/// Returns a Vec<JoinHandle<()>> as a tasks handles and a map of domain to ServerConfig for challenge.
pub fn spawn_manager_tasks(
&self,
term_notify: Option<Arc<tokio::sync::Notify>>,
cancel_token: Option<tokio_util::sync::CancellationToken>,
) -> (Vec<tokio::task::JoinHandle<()>>, HashMap<String, Arc<ServerConfig>>) {
let rustls_client_config = rustls::ClientConfig::builder()
.dangerous() // The `Verifier` we're using is actually safe
@ -96,7 +96,7 @@ impl AcmeManager {
let mut state = config.state();
server_configs_for_challenge.insert(domain.to_ascii_lowercase(), state.challenge_rustls_config());
self.runtime_handle.spawn({
let term_notify = term_notify.clone();
let cancel_token = cancel_token.clone();
async move {
info!("rpxy ACME manager task for {domain} started");
// infinite loop unless the return value is None
@ -112,10 +112,10 @@ impl AcmeManager {
}
}
};
if let Some(notify) = term_notify.as_ref() {
if let Some(cancel_token) = cancel_token.as_ref() {
tokio::select! {
_ = task => {},
_ = notify.notified() => { info!("rpxy ACME manager task for {domain} terminated") }
_ = cancel_token.cancelled() => { info!("rpxy ACME manager task for {domain} terminated") }
}
} else {
task.await;