Skip to content

Commit

Permalink
Add graceful shutdown to prometheus server (#1637)
Browse files Browse the repository at this point in the history
Fixes prometheus server not stopping if there are open connections
  • Loading branch information
tmpolaczyk authored Sep 21, 2023
1 parent 9e40362 commit a56fd32
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion substrate/utils/prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ async fn init_prometheus_with_listener(
}
});

let server = Server::builder(listener).serve(service);
let (signal, on_exit) = tokio::sync::oneshot::channel::<()>();
let server = Server::builder(listener).serve(service).with_graceful_shutdown(async {
let _ = on_exit.await;
});

let result = server.await.map_err(Into::into);

// Gracefully shutdown server, otherwise the server does not stop if it has open connections
let _ = signal.send(());

result
}

Expand Down

0 comments on commit a56fd32

Please sign in to comment.