Skip to content

Commit 6a2c892

Browse files
committed
admin: Fail connections when HTTP detection fails (#979)
fce8c4a updated the admin server to try to handle connections that fail HTTP detection. The intent of this was to handle connections that don't emit any HTTP request within the first few seconds of the connection. However, we also try to handle connections on which we have read data and affirmatively indicated that the connection is not HTTP. These connections manifest with errors about an invalid HTTP method, which can be ambiguous to users. This change handles this latter case explicitly with an error that describes the client so that users have better diagnostics without having to enable debug logging.
1 parent ba55373 commit 6a2c892

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

linkerd/app/src/admin.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct Admin {
3030
pub serve: Pin<Box<dyn std::future::Future<Output = ()> + Send + 'static>>,
3131
}
3232

33+
#[derive(Debug)]
34+
struct NonHttpClient(TcpAccept);
35+
3336
// === impl Config ===
3437

3538
impl Config {
@@ -65,14 +68,18 @@ impl Config {
6568
)
6669
.push_map_target(Target::from)
6770
.push(http::NewServeHttp::layer(Default::default(), drain.clone()))
68-
.push_map_target(
69-
|(version, tcp): (Result<Option<http::Version>, detect::DetectTimeout<_>>, _)| {
71+
.push_request_filter(
72+
|(version, tcp): (
73+
Result<Option<http::Version>, detect::DetectTimeout<_>>,
74+
TcpAccept,
75+
)| {
7076
match version {
71-
Ok(Some(version)) => HttpAccept::from((version, tcp)),
72-
Ok(None) | Err(_) => {
73-
debug!("Failed to parse HTTP request; handling as HTTP/1");
74-
HttpAccept::from((http::Version::Http1, tcp))
77+
Ok(Some(version)) => Ok(HttpAccept::from((version, tcp))),
78+
Err(_) => {
79+
debug!("HTTP detection timed out; handling as HTTP/1");
80+
Ok(HttpAccept::from((http::Version::Http1, tcp)))
7581
}
82+
Ok(None) => Err(NonHttpClient(tcp)),
7683
}
7784
},
7885
)
@@ -101,3 +108,17 @@ impl Config {
101108
})
102109
}
103110
}
111+
112+
// === impl NonHttpClient ===
113+
114+
impl std::fmt::Display for NonHttpClient {
115+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
116+
write!(
117+
f,
118+
"Non-HTTP connection from {} (tls={:?})",
119+
self.0.client_addr, self.0.tls
120+
)
121+
}
122+
}
123+
124+
impl std::error::Error for NonHttpClient {}

0 commit comments

Comments
 (0)