Skip to content

Commit

Permalink
fix: prometheus graceful shutdown (#8784)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and emhane committed Jun 13, 2024
1 parent 6206802 commit 865b259
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions crates/node-core/src/metrics/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::metrics::version_metrics::register_version_metrics;
use eyre::WrapErr;
use futures::{future::FusedFuture, FutureExt};
use http::Response;
use metrics::describe_gauge;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
Expand Down Expand Up @@ -65,17 +66,14 @@ async fn start_endpoint<F: Hook + 'static>(
tokio::net::TcpListener::bind(listen_addr).await.wrap_err("Could not bind to address")?;

task_executor.spawn_with_graceful_shutdown_signal(|signal| async move {
let mut shutdown = signal.ignore_guard();
let mut shutdown = signal.ignore_guard().fuse();
loop {
let io = tokio::select! {
res = listener.accept() => match res {
Ok((stream, _remote_addr)) => stream,
Err(err) => {
tracing::error!(%err, "failed to accept connection");
continue;
}
},
_ = &mut shutdown => break,
let io = match listener.accept().await {
Ok((stream, _remote_addr)) => stream,
Err(err) => {
tracing::error!(%err, "failed to accept connection");
continue;
}
};

let handle = handle.clone();
Expand All @@ -89,7 +87,11 @@ async fn start_endpoint<F: Hook + 'static>(
if let Err(error) =
jsonrpsee::server::serve_with_graceful_shutdown(io, service, &mut shutdown).await
{
tracing::error!(%error, "metrics endpoint crashed")
tracing::debug!(%error, "failed to serve request")
}

if shutdown.is_terminated() {
break;
}
}
});
Expand Down

0 comments on commit 865b259

Please sign in to comment.