mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: prometheus graceful shutdown (#8784)
This commit is contained in:
@ -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};
|
||||
@ -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();
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user