[bug] HTTP/2 readiness reads have no deadline: a silent peer parks the connection forever
Describe the bug
A downstream connection can stall permanently in the HTTP/2 readiness phase. When a peer sends fewer than the 24-byte HTTP/2 client preface, process_new waits on Stream::try_peek for h2c listeners or on h2's server handshake for TLS listeners with ALPN h2, and neither wait has a deadline. The connection task, its file descriptor, and its TLS session stay allocated until the peer acts or the process shuts down.
The only handshake deadline on this path is a 60-second timeout around io.handshake() in pingora-core/src/services/listening.rs, and it covers the transport and TLS handshake only. The HTTP/2 readiness reads run after that timeout, and the HTTP/2 idle timeout starts later still, so neither bounds them.
Two conditions reproduce the stall:
- Plaintext with
h2c: true: a client sends a complete but short HTTP/1.x request, for exampleGET / HTTP/1.0\r\n\r\n(18 bytes), and then waits for the response. The h2c sniff reads withread_exact(24)and waits for the 6 bytes that a finished client never sends. - TLS with ALPN h2: a client completes the TLS handshake and then sends nothing, so
h2::server::handshakewaits for the full preface.
Root cause
1. The 60-second handshake timeout covers the transport/TLS handshake only
// pingora-core/src/services/listening.rs:259-277 (abridged)
match new_io {
Ok(io) => {
let app = app_logic.clone();
let shutdown = shutdown.clone();
current_handle().spawn(async move {
let peer_addr = io.peer_addr();
match timeout(Duration::from_secs(60), io.handshake()).await {
Ok(handshake) => {
match handshake {
Ok(io) => Self::handle_event(io, app, shutdown).await,
Err(e) => { /* ... */ }
}
}
// ...io.handshake() performs the pre-TLS callback and the TLS handshake. handle_event, which reaches process_new, runs outside the timeout.
2. The h2c sniff waits for all 24 preface bytes without a deadline
// pingora-core/src/apps/mod.rs:292-312
if stream.get_ssl_digest().is_some() {
h2c = false;
}
// try to read h2 preface
else if h2c && !custom {
let mut buf = [0u8; H2_PREFACE.len()];
let peeked = stream
.try_peek(&mut buf)
.await
.map_err(|e| {
// this error is normal when h1 reuse and close the connection
debug!("Read error while peeking h2c preface {e}");
e
})
.ok()?;
// not all streams support peeking
if peeked {
// turn off h2c (use h1) if h2 preface doesn't exist
h2c = buf == H2_PREFACE;
}
}H2_PREFACE is the 24-byte string b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" (pingora-core/src/apps/mod.rs:35). For plaintext streams, try_peek reads with read_exact:
// pingora-core/src/protocols/l4/stream.rs:646-655
#[async_trait]
impl Peek for Stream {
async fn try_peek(&mut self, buf: &mut [u8]) -> std::io::Result<bool> {
use tokio::io::AsyncReadExt;
self.read_exact(buf).await?;
// rewind regardless of what is read
self.rewind(buf);
Ok(true)
}
}The trait contract says that the call should block until some data is sent, not until the whole buffer is filled:
// pingora-core/src/protocols/mod.rs:73-81
/// The ability peek data before consuming it
#[async_trait]
pub trait Peek {
/// Peek data but not consuming it. This call should block until some data
/// is sent.
/// Return `false` if peeking is not supported/allowed.
async fn try_peek(&mut self, _buf: &mut [u8]) -> std::io::Result<bool> {
Ok(false)
}
}An 18-byte request fills 18 of the 24 bytes, so read_exact returns Pending for the remaining 6 bytes. The client waits for a response, and neither side advances.
3. The h2 server handshake waits for the client preface without a deadline
// pingora-core/src/apps/mod.rs:313-330 (abridged)
if h2c || matches!(stream.selected_alpn_proto(), Some(ALPN::H2)) {
// ...
let h2_conn = match server::handshake(stream, h2_options).await {
Err(e) => {
error!("H2 handshake error {e}");
return None;
}
Ok(c) => c,
};// pingora-core/src/protocols/http/v2/server.rs:81-96
pub async fn handshake(io: Stream, options: Option<H2Options>) -> Result<H2Connection<Stream>> {
let options = options.unwrap_or_else(default_h2_options);
let res = options.handshake(io).await;
match res {
Ok(connection) => {
debug!("H2 handshake done.");
Ok(connection)
}
Err(e) => Error::e_because(
ErrorType::HandshakeError,
"while h2 handshaking with client",
e,
),
}
}The h2 documentation for server::Handshake states that the handshake completes only after the full connection preface is received from the client (h2 v0.4.16 and current main, src/server.rs:133-142). The workspace declares h2 = ">=0.4.16" in Cargo.toml. Therefore server::handshake stays pending while the peer sends nothing.
4. No later stage bounds these waits
The HTTP/2 idle timeout is passed to accept_downstream_sessions, which starts only after server::handshake returns:
// pingora-core/src/apps/mod.rs:337-359 (abridged)
let h2_idle_timeout = self.server_options().and_then(|o| o.h2_idle_timeout);
server::accept_downstream_sessions(
h2_conn,
digest,
shutdown.clone(),
h2_idle_timeout,
|h2_stream, guard| {
// ...
},
)
.await;The HTTP/1 session default read timeout is 60 seconds and applies to the HTTP/1 session, which the code creates after the sniff:
// pingora-core/src/protocols/http/v1/server.rs:183-191
proxy_task_state: ProxyTaskState::default(),
body_write_buf: BytesMut::new(),
keepalive_timeout: KeepaliveStatus::Off,
update_resp_headers: true,
response_written: None,
request_header: None,
read_timeout: Some(Duration::from_secs(60)),
write_timeout: None,
total_drain_timeout: None,TCP keepalive is optional on listeners (tcp_keepalive: Option<TcpKeepalive> in TcpSocketOptions) and is disabled by default. Graceful shutdown reclaims these tasks only when the process shuts down.
Pingora info
Pingora version: 0.9.0, main at 4487f7b2ab50f159e4a2cf4f6a6b813f61bb6e19
Rust version: nightly-2026-03-21 (toolchain used for the reproduction)
Operating system version: Linux on x86_64. The reproducer uses in-process duplex streams, so it is platform-independent.
Steps to reproduce
Save the file below as pingora-core/tests/h2_readiness_no_deadline.rs and run:
cargo +nightly-2026-03-21 test -p pingora-core --test h2_readiness_no_deadline -- --nocaptureOn the current tree both tests fail after the 5-second bound. That failure is the reproduction.
pingora-core/tests/h2_readiness_no_deadline.rs (runnable test file)// cargo +nightly-2026-03-21 test -p pingora-core --test h2_readiness_no_deadline -- --nocapture
use std::fmt;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::Duration;
use async_trait::async_trait;
use pingora_core::apps::{HttpServerApp, HttpServerOptions, ReusedHttpStream, ServerApp};
use pingora_core::protocols::http::v2::server;
use pingora_core::protocols::http::ServerSession;
use pingora_core::protocols::l4::stream::Stream as L4Stream;
use pingora_core::protocols::l4::virt::{VirtualSockOpt, VirtualSocket, VirtualSocketStream};
use pingora_core::protocols::Stream;
use pingora_core::server::ShutdownWatch;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
use tokio::time::timeout;
const BOUND: Duration = Duration::from_secs(5);
struct StallSocket {
inner: tokio::io::DuplexStream,
}
impl fmt::Debug for StallSocket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("StallSocket")
}
}
impl AsyncRead for StallSocket {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.inner).poll_read(cx, buf)
}
}
impl AsyncWrite for StallSocket {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
Pin::new(&mut self.inner).poll_write(cx, buf)
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.inner).poll_flush(cx)
}
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.inner).poll_shutdown(cx)
}
}
impl VirtualSocket for StallSocket {
fn set_socket_option(&self, _opt: VirtualSockOpt) -> std::io::Result<()> {
Ok(())
}
}
fn stalling_pair() -> (Stream, tokio::io::DuplexStream) {
let (server, client) = tokio::io::duplex(64 * 1024);
let stream = L4Stream::from(VirtualSocketStream::new(Box::new(StallSocket {
inner: server,
})));
(Box::new(stream), client)
}
struct TestApp {
options: HttpServerOptions,
}
impl TestApp {
fn new() -> Self {
let mut options = HttpServerOptions::default();
options.h2c = true;
Self { options }
}
}
#[async_trait]
impl HttpServerApp for TestApp {
async fn process_new_http(
self: &Arc<Self>,
_session: ServerSession,
_shutdown: &ShutdownWatch,
) -> Option<ReusedHttpStream> {
None
}
fn server_options(&self) -> Option<&HttpServerOptions> {
Some(&self.options)
}
}
#[tokio::test]
async fn h2c_sniff_short_http1_request_must_not_park_forever() {
let (io, mut client) = stalling_pair();
// Complete 18-byte HTTP/1.0 request, 6 bytes short of the h2 preface.
client.write_all(b"GET / HTTP/1.0\r\n\r\n").await.unwrap();
client.flush().await.unwrap();
let app = Arc::new(TestApp::new());
let (_shutdown_tx, shutdown) = tokio::sync::watch::channel(false);
let call = <TestApp as ServerApp<()>>::process_new(&app, io, &shutdown);
let outcome = timeout(BOUND, call).await;
drop(client);
assert!(
outcome.is_ok(),
"VULNERABILITY REPRODUCED: process_new() was still pending after 5s on an \
18-byte HTTP/1.0 request. The h2c preface sniff (apps/mod.rs:298 -> \
Stream::try_peek -> read_exact(24)) waits forever for the 6 bytes a \
finished client will never send."
);
}
#[tokio::test]
async fn h2_server_handshake_must_not_park_forever_on_a_silent_peer() {
let (io, _client) = stalling_pair();
let outcome = timeout(BOUND, server::handshake(io, None)).await;
assert!(
outcome.is_ok(),
"VULNERABILITY REPRODUCED: server::handshake() was still pending after 5s \
with a silent peer. The h2 server handshake waits for the full 24-byte \
client preface (h2 0.4.16 src/server.rs:133-142) without any read deadline."
);
}A wire-level reproduction is also possible:
- h2c: connect to a plaintext listener with
h2c: true, sendGET / HTTP/1.0\r\n\r\n(18 bytes), and keep the connection open. - TLS with ALPN h2: complete the TLS handshake with ALPN h2 and send nothing.
Expected results
The readiness phase is bounded. When the server cannot obtain a full preface, it falls back to HTTP/1 or closes the connection within a configured deadline, and no connection stays parked indefinitely.
Observed results
Both tests failed after the 5-second bound. The production waits remained pending for the whole bound, and the connection task kept the stream and its descriptor alive. No timeout, keepalive, or idle path interfered.
Test output (sanitized: prompt and file names normalized; line numbers refer to the revision used for the run)<user>@<host>:~/work/pingora$ cargo +nightly-2026-03-21 test -p pingora-core --test h2_readiness_no_deadline -- --nocapture
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.25s
Running tests/h2_readiness_no_deadline.rs (target/debug/deps/h2_readiness_no_deadline-cdc8bc3228d841ef)
running 2 tests
thread 'h2c_sniff_short_http1_request_must_not_park_forever' (558484) panicked at pingora-core/tests/h2_readiness_no_deadline.rs:154:5:
VULNERABILITY REPRODUCED: process_new() was still pending after 5s on an 18-byte HTTP/1.0 request. The h2c preface sniff (apps/mod.rs:298 -> Stream::try_peek -> read_exact(24)) waits forever for the 6 bytes a finished client will never send.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'h2_server_handshake_must_not_park_forever_on_a_silent_peer' (558483) panicked at pingora-core/tests/h2_readiness_no_deadline.rs:174:5:
VULNERABILITY REPRODUCED: server::handshake() was still pending after 5s with a silent peer. The h2 server handshake waits for the full 24-byte client preface (h2 0.4.16 src/server.rs:133-142) without any read deadline.
test h2c_sniff_short_http1_request_must_not_park_forever ... FAILED
test h2_server_handshake_must_not_park_forever_on_a_silent_peer ... FAILED
failures:
failures:
h2_server_handshake_must_not_park_forever_on_a_silent_peer
h2c_sniff_short_http1_request_must_not_park_forever
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.00s
error: test failed, to rerun pass `-p pingora-core --test h2_readiness_no_deadline`
<user>@<host>:~/work/pingora$Impact
A remote peer can park connections without credentials and without completing a request. Each parked connection holds one task, one file descriptor, and a TLS session on TLS listeners. The number of parked connections is bounded only by the peer, so sustained traffic can exhaust the file descriptor limit and prevent the listener from accepting new connections. The process does not reclaim them during normal operation. On an h2c listener, a complete 18-byte HTTP/1.0 request triggers the stall without malicious intent, because the client waits for a response while the server waits for 6 more bytes.
Source: cloudflare/pingora