fix(protocol-cache): Include requested_host in protocol detection cache key to avoid cache oscillation when multiple frontend domains share the same backend

This commit is contained in:
2026-03-08 15:24:18 +00:00
parent 4f1c5c919f
commit d4aa46aed7
4 changed files with 23 additions and 5 deletions

View File

@@ -593,6 +593,7 @@ impl HttpProxyService {
let cache_key = crate::protocol_cache::ProtocolCacheKey {
host: upstream.host.clone(),
port: upstream.port,
requested_host: host.clone(),
};
match self.protocol_cache.get(&cache_key) {
Some(crate::protocol_cache::DetectedProtocol::H2) => (true, false),
@@ -650,6 +651,7 @@ impl HttpProxyService {
let cache_key = crate::protocol_cache::ProtocolCacheKey {
host: upstream.host.clone(),
port: upstream.port,
requested_host: host.clone(),
};
let detected = if is_h2 {
crate::protocol_cache::DetectedProtocol::H2
@@ -721,6 +723,7 @@ impl HttpProxyService {
self.forward_h2_with_fallback(
io, parts, body, upstream_headers, &upstream_path,
&upstream, route_match.route, route_id, &ip_str, &final_pool_key,
host.clone(),
).await
} else {
// Explicit H2 mode: hard-fail on handshake error (preserved behavior)
@@ -907,6 +910,7 @@ impl HttpProxyService {
route_id: Option<&str>,
source_ip: &str,
pool_key: &crate::connection_pool::PoolKey,
requested_host: Option<String>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
let exec = hyper_util::rt::TokioExecutor::new();
let handshake_result: Result<(
@@ -961,6 +965,7 @@ impl HttpProxyService {
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);
Ok(error_response(StatusCode::BAD_GATEWAY, "Backend protocol mismatch, retrying with H1"))
@@ -979,6 +984,7 @@ impl HttpProxyService {
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);