fix(rustproxy-http): avoid downgrading cached backend protocol on H2 stream errors

This commit is contained in:
2026-03-17 01:32:35 +00:00
parent c2eacd1b30
commit 3baff354bd
3 changed files with 14 additions and 11 deletions

View File

@@ -1388,23 +1388,19 @@ impl HttpProxyService {
self.build_streaming_response(upstream_response, route, route_id, source_ip, conn_activity).await
}
Err(e) => {
// H2 request failed — backend advertises h2 via ALPN but doesn't
// actually speak it. Update cache so future requests use H1.
// H2 request failed on a stream level (e.g. RST_STREAM PROTOCOL_ERROR).
// The H2 handshake succeeded, so the backend genuinely speaks H2 — don't
// poison the protocol cache. Only handshake-level failures (below) should
// downgrade the cache to H1.
let bk = format!("{}:{}", upstream.host, upstream.port);
warn!(
debug!(
backend = %bk,
domain = %domain,
error = %e,
error_debug = ?e,
"Auto-detect: H2 request failed, falling back to H1"
"H2 stream error, retrying this request as H1"
);
self.metrics.backend_h2_failure(&bk);
let cache_key = crate::protocol_cache::ProtocolCacheKey {
host: upstream.host.clone(),
port: upstream.port,
requested_host: requested_host.clone(),
};
self.protocol_cache.insert(cache_key, crate::protocol_cache::DetectedProtocol::H1);
// Retry as H1 for bodyless requests; return 502 for requests with bodies
if let Some((method, headers)) = retry_state {