diff --git a/Cargo.toml b/Cargo.toml index d87e072..79b5ba9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ default_features = false optional = true version = "0.7.0" default_features = false +features = ["process"] [features] default = ["metrics"] diff --git a/src/metrics.rs b/src/metrics.rs index 53e039a..31914d7 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -10,8 +10,11 @@ use hyper::{Body, Request, Response, StatusCode}; use prometheus::{self, Encoder, TextEncoder}; use std::sync::Arc; use tokio::net::TcpListener; +use tokio::prelude::*; use tokio::runtime::Runtime; +const METRICS_CONNECTION_TIMEOUT_SECS: u64 = 10; + async fn handle_client_connection( req: Request, varz: Varz, @@ -60,7 +63,13 @@ pub async fn prometheus_service( let service = service_fn(move |req| handle_client_connection(req, varz.clone(), path.clone())); let connection = Http::new().serve_connection(client, service); - runtime.spawn(connection.map(|_| {})); + runtime.spawn( + connection + .timeout(std::time::Duration::from_secs( + METRICS_CONNECTION_TIMEOUT_SECS, + )) + .map(|_| {}), + ); } Ok(()) }