diff --git a/dynamic-proxy/src/server.rs b/dynamic-proxy/src/server.rs index 4a65bddca..54c8b2e2d 100644 --- a/dynamic-proxy/src/server.rs +++ b/dynamic-proxy/src/server.rs @@ -216,6 +216,10 @@ impl SimpleHttpServer { impl Drop for SimpleHttpServer { fn drop(&mut self) { + if self.graceful_shutdown.is_some() { + tracing::warn!("Shutting down SimpleHttpServer without a call to graceful_shutdown. Connections will be dropped abruptly!"); + } + self.handle.abort(); } } diff --git a/dynamic-proxy/tests/graceful.rs b/dynamic-proxy/tests/graceful.rs index 5597fb28d..0b15541f6 100644 --- a/dynamic-proxy/tests/graceful.rs +++ b/dynamic-proxy/tests/graceful.rs @@ -7,10 +7,17 @@ use std::net::SocketAddr; use tokio::net::TcpListener; use tokio::time::Duration; -mod common; - // Ref: https://github.com/hyperium/hyper-util/blob/master/examples/server_graceful.rs +async fn slow_hello_world( + _: hyper::Request, +) -> Result, Infallible> { + tokio::time::sleep(Duration::from_secs(1)).await; // emulate slow request + let body = http_body_util::Full::::from("Hello, world!".to_owned()); + let body = to_simple_body(body); + Ok(hyper::Response::new(body)) +} + #[tokio::test] async fn test_graceful_shutdown() { // Start the server @@ -18,12 +25,7 @@ async fn test_graceful_shutdown() { let listener = TcpListener::bind(addr).await.unwrap(); let addr = listener.local_addr().unwrap(); let server = SimpleHttpServer::new( - hyper::service::service_fn(|_| async move { - tokio::time::sleep(Duration::from_secs(1)).await; // emulate slow request - let body = http_body_util::Full::::from("Hello, world!".to_owned()); - let body = to_simple_body(body); - Ok::<_, Infallible>(hyper::Response::new(body)) - }), + hyper::service::service_fn(slow_hello_world), listener, HttpsConfig::Http, )