Like [Self::load_context] but attempts to reload the files each time `ticker` yields an item. Returns an error based on the files currently on disk. When `ticker` receives, the certificates are reloaded from the context. The result of the reloading is returned on the oneshot if present, and an Ok result means new connections will use the new certificates. An Err result will not change the current
(
&self,
mut ticker: ReloadTrigger,
)
| 503 | /// oneshot if present, and an Ok result means new connections will use the new certificates. An |
| 504 | /// Err result will not change the current certificates. |
| 505 | pub fn reloading_context( |
| 506 | &self, |
| 507 | mut ticker: ReloadTrigger, |
| 508 | ) -> Result<ReloadingSslContext, anyhow::Error> { |
| 509 | let context = Arc::new(RwLock::new(self.load_context()?)); |
| 510 | let updater_context = Arc::clone(&context); |
| 511 | let config = self.clone(); |
| 512 | mz_ore::task::spawn(|| "TlsCertConfig reloading_context", async move { |
| 513 | while let Some(chan) = ticker.next().await { |
| 514 | let result = match config.load_context() { |
| 515 | Ok(ctx) => { |
| 516 | *updater_context.write().expect("poisoned") = ctx; |
| 517 | Ok(()) |
| 518 | } |
| 519 | Err(err) => { |
| 520 | tracing::error!("failed to reload SSL certificate: {err}"); |
| 521 | Err(err) |
| 522 | } |
| 523 | }; |
| 524 | if let Some(chan) = chan { |
| 525 | let _ = chan.send(result); |
| 526 | } |
| 527 | } |
| 528 | tracing::warn!("TlsCertConfig reloading_context updater closed"); |
| 529 | }); |
| 530 | Ok(ReloadingSslContext { context }) |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /// An SslContext whose inner value can be updated. |