server: fix connection counter
This commit is contained in:
@@ -121,29 +121,40 @@ fn spawn_watchdog_task(duration: Duration) -> JoinHandle<()> {
|
|||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
if let Err(err) = sd_notify::notify(false, &[sd_notify::NotifyState::Watchdog]) {
|
if let Err(err) = sd_notify::notify(false, &[sd_notify::NotifyState::Watchdog]) {
|
||||||
log::warn!("Failed to notify systemd watchdog: {}", err);
|
log::warn!("Failed to notify systemd watchdog: {}", err);
|
||||||
} else {
|
|
||||||
log::trace!("Ping sent to systemd watchdog");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_status_notifier_task(connection_counter: std::sync::Arc<()>) -> JoinHandle<()> {
|
fn spawn_status_notifier_task(connection_counter: std::sync::Arc<()>) -> JoinHandle<()> {
|
||||||
const NON_CONNECTION_ARC_COUNT: usize = 4;
|
const NON_CONNECTION_ARC_COUNT: usize = 3;
|
||||||
const STATUS_UPDATE_INTERVAL_SECS: Duration = Duration::from_secs(1);
|
const STATUS_UPDATE_INTERVAL_SECS: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut interval = interval(STATUS_UPDATE_INTERVAL_SECS);
|
let mut interval = interval(STATUS_UPDATE_INTERVAL_SECS);
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
log::trace!("Updating systemd status notification");
|
let count = match Arc::strong_count(&connection_counter)
|
||||||
let count = Arc::strong_count(&connection_counter) - NON_CONNECTION_ARC_COUNT;
|
.checked_sub(NON_CONNECTION_ARC_COUNT)
|
||||||
|
{
|
||||||
|
Some(c) => c,
|
||||||
|
None => {
|
||||||
|
debug_assert!(false, "Connection counter calculation underflowed");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let message = if count > 0 {
|
let message = if count > 0 {
|
||||||
format!("Handling {} connections", count)
|
format!("Handling {} connections", count)
|
||||||
} else {
|
} else {
|
||||||
"Waiting for connections".to_string()
|
"Waiting for connections".to_string()
|
||||||
};
|
};
|
||||||
sd_notify::notify(false, &[sd_notify::NotifyState::Status(message.as_str())]).ok();
|
|
||||||
|
if let Err(e) =
|
||||||
|
sd_notify::notify(false, &[sd_notify::NotifyState::Status(message.as_str())])
|
||||||
|
{
|
||||||
|
log::warn!("Failed to send systemd status notification: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user