Skip to content

Commit 110e9be

Browse files
authored
admin: Handle connections that fail protocol detection (#960)
The HTTP detect module may fail to detect an HTTP protocol if the first read does not return at least 14 bytes. This has caused spurious failures as described in linkerd/linkerd2#5672. This change updates the admin server's protocol detection to handle these connections as HTTP/1 so that the HTTP server can try to process them and fail on its own if the connection really is not HTTP.
1 parent bb00dc6 commit 110e9be

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

linkerd/app/src/admin.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use crate::{
1313
inbound::target::{HttpAccept, Target, TcpAccept},
1414
svc,
1515
};
16-
use std::{fmt, net::SocketAddr, pin::Pin, time::Duration};
16+
use std::{net::SocketAddr, pin::Pin, time::Duration};
1717
use tokio::sync::mpsc;
18+
use tracing::debug;
1819

1920
#[derive(Clone, Debug)]
2021
pub struct Config {
@@ -28,9 +29,6 @@ pub struct Admin {
2829
pub serve: Pin<Box<dyn std::future::Future<Output = ()> + Send + 'static>>,
2930
}
3031

31-
#[derive(Debug, Default)]
32-
pub struct AdminHttpOnly(());
33-
3432
// === impl Config ===
3533

3634
impl Config {
@@ -62,15 +60,17 @@ impl Config {
6260
)
6361
.push_map_target(Target::from)
6462
.push(http::NewServeHttp::layer(Default::default(), drain.clone()))
65-
.push(svc::Filter::<TcpAccept, _>::layer(
63+
.push_map_target(
6664
|(version, tcp): (Result<Option<http::Version>, detect::DetectTimeout<_>>, _)| {
6765
match version {
68-
Ok(Some(version)) => Ok(HttpAccept::from((version, tcp))),
69-
Ok(None) => Err(Error::from(AdminHttpOnly(()))),
70-
Err(timeout) => Err(Error::from(timeout)),
66+
Ok(Some(version)) => HttpAccept::from((version, tcp)),
67+
Ok(None) | Err(_) => {
68+
debug!("Failed to parse HTTP request; handling as HTTP/1");
69+
HttpAccept::from((http::Version::Http1, tcp))
70+
}
7171
}
7272
},
73-
))
73+
)
7474
.push(detect::NewDetectService::layer(
7575
DETECT_TIMEOUT,
7676
http::DetectHttp::default(),
@@ -89,13 +89,3 @@ impl Config {
8989
})
9090
}
9191
}
92-
93-
// === impl AdminHttpOnly ===
94-
95-
impl fmt::Display for AdminHttpOnly {
96-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97-
f.pad("proxy admin server is HTTP-only")
98-
}
99-
}
100-
101-
impl std::error::Error for AdminHttpOnly {}

0 commit comments

Comments
 (0)