Pre shutdown hooks for GatewayClient (#5381)

This commit is contained in:
Drazen Urch
2025-01-27 20:00:37 +01:00
committed by GitHub
parent ff91d4619e
commit 9550934d1f
9 changed files with 112 additions and 50 deletions
+12 -4
View File
@@ -59,9 +59,6 @@ async fn make_clients(
loop {
if Arc::strong_count(&dropped_client) == 1 {
if let Some(client) = Arc::into_inner(dropped_client) {
// let forget_me = ClientRequest::ForgetMe {
// also_from_stats: true,
// };
let client_handle = client.into_inner();
client_handle.disconnect().await;
} else {
@@ -222,10 +219,12 @@ async fn main() -> Result<()> {
TOPOLOGY.get().expect("Topology not set yet!").clone(),
));
let clients_server = clients.clone();
let server_handle = tokio::spawn(async move {
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::from_str(&args.host)?), args.port);
let server = HttpServer::new(socket, server_cancel_token);
server.run(clients).await
server.run(clients_server).await
});
info!("Waiting for message (ctrl-c to exit)");
@@ -259,6 +258,15 @@ async fn main() -> Result<()> {
};
}
info!("Disconnecting all clients");
let mut clients_guard = clients.write().await;
while let Some(client) = clients_guard.pop_front() {
if let Some(client) = Arc::into_inner(client) {
let client_handle = client.into_inner();
client_handle.disconnect().await;
}
}
cancel_token.cancel();
server_handle.await??;