From 41a88beb8dcd0427b83672390242bb11f542479b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Mon, 8 Jan 2024 14:08:10 +0100 Subject: [PATCH] chore(tls-reload): Improve tls reloading & remove deps on rust 1.75 --- src/tunnel/tls_reloader.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tunnel/tls_reloader.rs b/src/tunnel/tls_reloader.rs index 47ae570..37c9581 100644 --- a/src/tunnel/tls_reloader.rs +++ b/src/tunnel/tls_reloader.rs @@ -3,12 +3,11 @@ use anyhow::Context; use log::trace; use notify::{EventKind, RecommendedWatcher, Watcher}; use parking_lot::Mutex; -use std::fs::File; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread; -use std::time::{Duration, SystemTime}; +use std::time::Duration; use tracing::{error, info, warn}; struct TlsReloaderState { @@ -83,13 +82,13 @@ impl TlsReloader { }; drop(watcher); - let Ok(file) = File::open(&path) else { - return; + // Generate a fake event to force-reload the certificate + let event = notify::Event { + kind: EventKind::Create(notify::event::CreateKind::Any), + paths: vec![path], + attrs: Default::default(), }; - let _ = file.set_modified(SystemTime::now()).map_err(|err| { - error!("Cannot force reload TLS file {:?}: {:?}", path, err); - error!("Old certificate will be used until the next change"); - }); + Self::handle_fs_event(&this, Ok(event)); }); } @@ -116,6 +115,7 @@ impl TlsReloader { } Err(err) => { warn!("Error while loading TLS certificate {:?}", err); + Self::try_rewatch_certificate(this.clone(), path.to_path_buf()); } }, EventKind::Remove(_) => { @@ -137,6 +137,7 @@ impl TlsReloader { } Err(err) => { warn!("Error while loading TLS private key {:?}", err); + Self::try_rewatch_certificate(this.clone(), path.to_path_buf()); } }, EventKind::Remove(_) => {