Gracefully shutdown if LDAP connection is lost

This commit is contained in:
2025-04-20 00:24:32 +02:00
parent 7851d6bb12
commit c7b0cfc888
2 changed files with 13 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ use russh::keys::PublicKey;
use tokio::select;
use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
use tracing::{debug, warn};
use tracing::{debug, error};
#[derive(Debug, Clone)]
pub struct Ldap {
@@ -51,9 +51,10 @@ impl Ldap {
select! {
res = conn.drive() => {
if let Err(err) = res {
warn!("LDAP connection error: {}", err);
error!("LDAP connection error: {}", err);
} else {
debug!("LDAP drive has stopped, this should not happen?");
error!("LDAP connection lost");
token.cancel();
}
}
_ = token.cancelled() => {