Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept concurrent prometheus connections #9459

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading