Skip to content

Commit f423f9f

Browse files
tmpolaczykdudo50
authored andcommitted
Fix metrics not shutting down if there are open connections (paritytech#6220)
Fix prometheus metrics not shutting down if there are open connections. I fixed the same issue in the past but it broke again after a dependecy upgrade. See also: paritytech#1637
1 parent bb4ee10 commit f423f9f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

prdoc/pr_6220.prdoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: Fix metrics not shutting down if there are open connections
2+
3+
doc:
4+
- audience: Runtime Dev
5+
description: |
6+
Fix prometheus metrics not shutting down if there are open connections
7+
8+
crates:
9+
- name: substrate-prometheus-endpoint
10+
bump: patch

substrate/utils/prometheus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1818
[dependencies]
1919
http-body-util = { workspace = true }
2020
hyper = { features = ["http1", "server"], workspace = true }
21-
hyper-util = { features = ["server-auto", "tokio"], workspace = true }
21+
hyper-util = { features = ["server-auto", "server-graceful", "tokio"], workspace = true }
2222
log = { workspace = true, default-features = true }
2323
prometheus = { workspace = true }
2424
thiserror = { workspace = true }

substrate/utils/prometheus/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async fn init_prometheus_with_listener(
102102
log::info!(target: "prometheus", "〽️ Prometheus exporter started at {}", listener.local_addr()?);
103103

104104
let server = hyper_util::server::conn::auto::Builder::new(hyper_util::rt::TokioExecutor::new());
105+
let graceful = hyper_util::server::graceful::GracefulShutdown::new();
105106

106107
loop {
107108
let io = match listener.accept().await {
@@ -120,6 +121,7 @@ async fn init_prometheus_with_listener(
120121
hyper::service::service_fn(move |req| request_metrics(req, registry.clone())),
121122
)
122123
.into_owned();
124+
let conn = graceful.watch(conn);
123125

124126
tokio::spawn(async move {
125127
if let Err(err) = conn.await {

0 commit comments

Comments
 (0)