Skip to content

Commit 2989101

Browse files
authored
chore(proxy/http): address hyper::client::conn::Builder deprecations (#3427)
this branch contains a sequence of commits that focus on addressing deprecation warnings related to hyper::client::conn::Builder. this branch enables the backports feature, and then replaces some of these builders with the backported, http/2 specific, hyper::client::conn::http2::Builder type. relates to linkerd/linkerd2#8733. --- * chore(proxy/http): address `h2::Connection` deprecation this commit updates `Connection<B>` to use the backported, http/2 specific `SendRequest` type. this commit enables the `backports` feature flag in the `hyper` dependency. Signed-off-by: katelyn martin <kate@buoyant.io> * chore(proxy/http): address `server::tests` deprecations Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(proxy/http): consolidate connect functions `connect()` is never called elsewhere. let's avoid the misdirection and move it into the body of `connect_h2()`. Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent c8f7ca1 commit 2989101

File tree

3 files changed

+34
-44
lines changed

3 files changed

+34
-44
lines changed

linkerd/proxy/http/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ http = "0.2"
2121
http-body = "0.4"
2222
httparse = "1"
2323
hyper = { version = "0.14", features = [
24+
"backports",
2425
"client",
2526
"deprecated",
2627
"http1",

linkerd/proxy/http/src/h2.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::TracingExecutor;
22
use futures::prelude::*;
3-
use hyper::{body::HttpBody, client::conn};
3+
use hyper::body::HttpBody;
44
use linkerd_error::{Error, Result};
55
use linkerd_stack::{MakeConnection, Service};
66
use std::{
@@ -23,8 +23,7 @@ pub struct Connect<C, B> {
2323

2424
#[derive(Debug)]
2525
pub struct Connection<B> {
26-
#[allow(deprecated)] // linkerd/linkerd2#8733
27-
tx: hyper::client::conn::SendRequest<B>,
26+
tx: hyper::client::conn::http2::SendRequest<B>,
2827
}
2928

3029
// === impl Connect ===
@@ -87,21 +86,19 @@ where
8786
Box::pin(
8887
async move {
8988
let (io, _meta) = connect.err_into::<Error>().await?;
90-
#[allow(deprecated)] // linkerd/linkerd2#8733
91-
let mut builder = conn::Builder::new();
92-
builder.executor(TracingExecutor).http2_only(true);
89+
let mut builder = hyper::client::conn::http2::Builder::new(TracingExecutor);
9390
match flow_control {
9491
None => {}
9592
Some(FlowControl::Adaptive) => {
96-
builder.http2_adaptive_window(true);
93+
builder.adaptive_window(true);
9794
}
9895
Some(FlowControl::Fixed {
9996
initial_stream_window_size,
10097
initial_connection_window_size,
10198
}) => {
10299
builder
103-
.http2_initial_stream_window_size(initial_stream_window_size)
104-
.http2_initial_connection_window_size(initial_connection_window_size);
100+
.initial_stream_window_size(initial_stream_window_size)
101+
.initial_connection_window_size(initial_connection_window_size);
105102
}
106103
}
107104

@@ -113,17 +110,17 @@ where
113110
}) = keep_alive
114111
{
115112
builder
116-
.http2_keep_alive_timeout(timeout)
117-
.http2_keep_alive_interval(interval)
118-
.http2_keep_alive_while_idle(while_idle);
113+
.keep_alive_timeout(timeout)
114+
.keep_alive_interval(interval)
115+
.keep_alive_while_idle(while_idle);
119116
}
120117

121-
builder.http2_max_frame_size(max_frame_size);
118+
builder.max_frame_size(max_frame_size);
122119
if let Some(max) = max_concurrent_reset_streams {
123-
builder.http2_max_concurrent_reset_streams(max);
120+
builder.max_concurrent_reset_streams(max);
124121
}
125122
if let Some(sz) = max_send_buf_size {
126-
builder.http2_max_send_buf_size(sz);
123+
builder.max_send_buf_size(sz);
127124
}
128125

129126
let (tx, conn) = builder
@@ -153,7 +150,7 @@ where
153150
{
154151
type Response = http::Response<hyper::Body>;
155152
type Error = hyper::Error;
156-
type Future = conn::ResponseFuture;
153+
type Future = Pin<Box<dyn Send + Future<Output = Result<Self::Response, Self::Error>>>>;
157154

158155
#[inline]
159156
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@@ -175,6 +172,6 @@ where
175172
*req.version_mut() = http::Version::HTTP_11;
176173
}
177174

178-
self.tx.send_request(req)
175+
self.tx.send_request(req).boxed()
179176
}
180177
}

linkerd/proxy/http/src/server/tests.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::vec;
22

33
use super::*;
44
use bytes::Bytes;
5+
use futures::FutureExt;
56
use http_body::Body;
67
use linkerd_stack::CloneParam;
78
use tokio::time;
@@ -26,10 +27,9 @@ async fn h2_connection_window_exhaustion() {
2627
h2::ServerParams::default(),
2728
// An HTTP/2 client with constrained connection and stream windows to
2829
// force window exhaustion.
29-
#[allow(deprecated)] // linkerd/linkerd2#8733
30-
hyper::client::conn::Builder::new()
31-
.http2_initial_connection_window_size(CLIENT_CONN_WINDOW)
32-
.http2_initial_stream_window_size(CLIENT_STREAM_WINDOW),
30+
hyper::client::conn::http2::Builder::new(TracingExecutor)
31+
.initial_connection_window_size(CLIENT_CONN_WINDOW)
32+
.initial_stream_window_size(CLIENT_STREAM_WINDOW),
3333
)
3434
.await;
3535

@@ -100,8 +100,8 @@ async fn h2_stream_window_exhaustion() {
100100
// A basic HTTP/2 server configuration with no overrides.
101101
h2::ServerParams::default(),
102102
// An HTTP/2 client with stream windows to force window exhaustion.
103-
#[allow(deprecated)] // linkerd/linkerd2#8733
104-
hyper::client::conn::Builder::new().http2_initial_stream_window_size(CLIENT_STREAM_WINDOW),
103+
hyper::client::conn::http2::Builder::new(TracingExecutor)
104+
.initial_stream_window_size(CLIENT_STREAM_WINDOW),
105105
)
106106
.await;
107107

@@ -144,8 +144,7 @@ async fn h2_stream_window_exhaustion() {
144144
const LOG_LEVEL: &str = "h2::proto=trace,hyper=trace,linkerd=trace,info";
145145

146146
struct TestServer {
147-
#[allow(deprecated)] // linkerd/linkerd2#8733
148-
client: hyper::client::conn::SendRequest<BoxBody>,
147+
client: hyper::client::conn::http2::SendRequest<BoxBody>,
149148
server: Handle,
150149
}
151150

@@ -184,8 +183,16 @@ async fn timeout<F: Future>(inner: F) -> Result<F::Output, time::error::Elapsed>
184183

185184
impl TestServer {
186185
#[tracing::instrument(skip_all)]
187-
#[allow(deprecated)] // linkerd/linkerd2#8733
188-
async fn connect(params: Params, client: &mut hyper::client::conn::Builder) -> Self {
186+
async fn connect_h2(
187+
h2: h2::ServerParams,
188+
client: &mut hyper::client::conn::http2::Builder,
189+
) -> Self {
190+
let params = Params {
191+
drain: drain(),
192+
version: Version::H2,
193+
http2: h2,
194+
};
195+
189196
// Build the HTTP server with a mocked inner service so that we can handle
190197
// requests.
191198
let (mock, server) = mock::pair();
@@ -196,7 +203,6 @@ impl TestServer {
196203

197204
// Build a real HTTP/2 client using the mocked socket.
198205
let (client, task) = client
199-
.executor(crate::TracingExecutor)
200206
.handshake::<_, BoxBody>(cio)
201207
.await
202208
.expect("client connect");
@@ -205,21 +211,6 @@ impl TestServer {
205211
Self { client, server }
206212
}
207213

208-
#[allow(deprecated)] // linkerd/linkerd2#8733
209-
async fn connect_h2(h2: h2::ServerParams, client: &mut hyper::client::conn::Builder) -> Self {
210-
Self::connect(
211-
// A basic HTTP/2 server configuration with no overrides.
212-
Params {
213-
drain: drain(),
214-
version: Version::H2,
215-
http2: h2,
216-
},
217-
// An HTTP/2 client with constrained connection and stream windows to accomodate
218-
client.http2_only(true),
219-
)
220-
.await
221-
}
222-
223214
/// Issues a request through the client to the mocked server and processes the
224215
/// response. The mocked response body sender and the readable response body are
225216
/// returned.
@@ -228,7 +219,8 @@ impl TestServer {
228219
self.server.allow(1);
229220
let mut call0 = self
230221
.client
231-
.send_request(http::Request::new(BoxBody::default()));
222+
.send_request(http::Request::new(BoxBody::default()))
223+
.boxed();
232224
let (_req, next) = tokio::select! {
233225
_ = (&mut call0) => unreachable!("client cannot receive a response"),
234226
next = self.server.next_request() => next.expect("server not dropped"),

0 commit comments

Comments
 (0)