Skip to content

Commit

Permalink
fix: accept concurrent prometheus connections (#9459)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 11, 2024
1 parent 22df39a commit 95bde32
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions crates/node/core/src/metrics/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::metrics::version_metrics::VersionInfo;
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,14 +64,18 @@ async fn start_endpoint<F: Hook + 'static>(
let listener =
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().fuse();
task_executor.spawn_with_graceful_shutdown_signal(|mut signal| async move {
loop {
let io = match listener.accept().await {
Ok((stream, _remote_addr)) => stream,
Err(err) => {
tracing::error!(%err, "failed to accept connection");
continue;
let io = tokio::select! {
_ = &mut signal => break,
io = listener.accept() => {
match io {
Ok((stream, _remote_addr)) => stream,
Err(err) => {
tracing::error!(%err, "failed to accept connection");
continue;
}
}
}
};

Expand All @@ -84,15 +87,15 @@ async fn start_endpoint<F: Hook + 'static>(
async move { Ok::<_, Infallible>(Response::new(metrics)) }
});

if let Err(error) =
jsonrpsee::server::serve_with_graceful_shutdown(io, service, &mut shutdown).await
{
tracing::debug!(%error, "failed to serve request")
}

if shutdown.is_terminated() {
break;
}
let mut shutdown = signal.clone().ignore_guard();
tokio::task::spawn(async move {
if let Err(error) =
jsonrpsee::server::serve_with_graceful_shutdown(io, service, &mut shutdown)
.await
{
tracing::debug!(%error, "failed to serve request")
}
});
}
});

Expand Down

0 comments on commit 95bde32

Please sign in to comment.