Skip to content

fix: skip h2c preface detection on TLS streams#826

Open
cph816 wants to merge 2 commits intocloudflare:mainfrom
cph816:cph816/fix-h2c-tls
Open

fix: skip h2c preface detection on TLS streams#826
cph816 wants to merge 2 commits intocloudflare:mainfrom
cph816:cph816/fix-h2c-tls

Conversation

@cph816
Copy link

@cph816 cph816 commented Mar 2, 2026

h2c (HTTP/2 cleartext) preface detection should only run on cleartext TCP connections. On TLS, ALPN negotiates the protocol during the handshake.

When h2c is enabled and both TCP and TLS listeners share a service, preface detection runs on TLS streams too. On TLS, try_peek returns peeked=false, leaving h2c=true unconditionally. This forces all TLS connections into the HTTP/2 branch, breaking HTTP/1.1 clients.

Fix: check get_ssl_digest().is_some() to detect TLS and skip h2c detection, letting the existing ALPN check decide the protocol.

Verification:

test_h1_tls_with_h2c_enabled fails without this fix

Reproduction

  1. Create a Pingora HTTP proxy service with h2c = true
  2. Add both TCP and TLS listeners to the same service
  3. Send an HTTP/1.1 request to the TLS port (e.g., curl --http1.1 https://...)

HTTP/2 requests to the TLS port (via ALPN) work fine.
HTTP/1.1 requests to the TCP port also work fine (h2c peek correctly detects HTTP/1.1

h2c (HTTP/2 cleartext) preface detection should only run on cleartext
TCP connections. On TLS, ALPN negotiates the protocol during the
handshake.

When h2c is enabled and both TCP and TLS listeners share a service,
preface detection runs on TLS streams too. On TLS, try_peek returns
peeked=false, leaving h2c=true unconditionally. This forces all TLS
connections into the HTTP/2 branch, breaking HTTP/1.1 clients.

Fix: check get_ssl_digest().is_some() to detect TLS and skip h2c
detection, letting the existing ALPN check decide the protocol.
@cph816 cph816 force-pushed the cph816/fix-h2c-tls branch from fba40db to c1af22d Compare March 3, 2026 23:59
@cph816 cph816 force-pushed the cph816/fix-h2c-tls branch from c1af22d to 08af462 Compare March 4, 2026 00:12
@drcaramelsyrup drcaramelsyrup added bug Something isn't working enhancement New feature or request and removed enhancement New feature or request labels Mar 6, 2026
@andrewhavck andrewhavck self-assigned this Mar 13, 2026
@andrewhavck andrewhavck added the Accepted This change is accepted by us and merged to our internal repo label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accepted This change is accepted by us and merged to our internal repo bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants