add some interruption points in recursive event handling to prevent shutdown hangs

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-10-22 07:15:28 +00:00 committed by strawberry
parent dd6621a720
commit b08c1241a8
3 changed files with 15 additions and 4 deletions

View file

@ -5,7 +5,7 @@ use std::{
use tokio::{runtime, sync::broadcast};
use crate::{config::Config, log::Log, metrics::Metrics, Err, Result};
use crate::{config::Config, err, log::Log, metrics::Metrics, Err, Result};
/// Server runtime state; public portion
pub struct Server {
@ -107,6 +107,13 @@ impl Server {
.expect("runtime handle available in Server")
}
#[inline]
pub fn check_running(&self) -> Result {
self.running()
.then_some(())
.ok_or_else(|| err!(debug_warn!("Server is shutting down.")))
}
#[inline]
pub fn running(&self) -> bool { !self.stopping.load(Ordering::Acquire) }