From 3c0eb1bf71b24ba75b03d79ff444abba4ef5cb98 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 10 Mar 2024 09:32:26 +0000 Subject: [PATCH] add timeout for read_version --- proxy/src/serverless.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/proxy/src/serverless.rs b/proxy/src/serverless.rs index 0b8f42cd46..56e2418af2 100644 --- a/proxy/src/serverless.rs +++ b/proxy/src/serverless.rs @@ -167,12 +167,20 @@ pub async fn task_main( let (version, conn) = match conn.get_ref().1.alpn_protocol() { Some(b"http/1.1") => (http_auto::Version::H1, Rewind::new(conn)), Some(b"h2") => (http_auto::Version::H2, Rewind::new(conn)), - _ => match http_auto::read_version(conn).await { - Ok(v) => v, - Err(e) => { - tracing::warn!("HTTP connection error {e}"); - return; - }, + _ => { + tracing::debug!("HTTP: no ALPN negotiated"); + let conn = timeout(Duration::from_secs(10), http_auto::read_version(conn)).await; + match conn { + Ok(Ok(v)) => v, + Ok(Err(e)) => { + tracing::warn!("HTTP connection error: {e}"); + return; + }, + Err(_) => { + tracing::warn!("HTTP connection error: timeout determining http version"); + return; + } + } } };