Skip to content

Commit 3defe3d

Browse files
authored
update to Tokio 1.0 (#826)
This branch updates the proxy to Tokio 1.0 and its ecosystem, including: - `tokio` 1.0 (obviously) - the `tokio` 1.0 versions of `tokio-test` and `tokio-util` - `bytes` 1.0 - `tower` 0.4 - `hyper` 0.14.2 - `h2` 0.3 - `tonic`, via git dependency - `prost` 0.7 - `tokio-rustls` 0.22 - `rustls` 0.19 - `trust-dns-resolver` 0.20 - `linkerd2-proxy-api`, via git dependency - `rand` 0.8 For the most part, the change here is pretty straightforward, just updating the specified dependency versions. The API changes in `tokio` were mostly made in 0.3, so we have already tracked most of them. However, the following small changes were necessary: - Hyper now has feature flags that must be enabled. - `bytes` renamed `Buf::bytes` and `Buf::bytes_vectored` and `BufMut::bytes_mut` to `chunk`, `chunk_vectored`, and `chunk_mut`, respectively. - `tokio::sync::Semaphore` now has a `close` method, and `acquire` returns a `Result`. Updated `linkerd2-channel` to track this. This also allowed removing some kind of janky jury-rigged code for closing a semaphore. - The `tokio::Runtime::builder::max_threads` method was renamed to `max_blocking_threads`. There were also a couple of larger changes. In particular: - `tokio` no longer re-exports the `Stream` trait from `Futures`, for stability reasons. I added a wrapper API for implementing `Stream` for `mpsc` receivers and for `tokio::time::Interval`. - `tokio::time::Sleep` is now `!Unpin`, since it no longer contains an internal heap allocation. This reduces heap overhead when used with async/await syntax. However, for manual `Future` and `tower::Service` impls, the `Box` must be added _outside_ the `Sleep` to preserve `Unpin`nedness. I've done this in all places where it was necessary. I also changed some `Service` impls (`failfast` and `switch_ready`) which repeatedly create new `Sleep` futures, to use `Sleep::reset` instead, allowing them to avoid reallocations. This also means that `tower`'s `Timeout` middleware's future is no longer `Unpin`. Since connect futures are required to be `Unpin`, and the connect stacks contain timeout layers, I added a new `BoxResponse` middleware layer for boxing *just* response futures, while preserving the type of the wrapped `Service` (so that connect stacks are still `Clone`). - Removed the `linkerd-app-profiling` crate, which has bit-rotted. The latest `tower` release also adds upstream implementations of a number of middlewares we've written our own versions of. As a follow-up, we probably want to replace some of this stuff with the upstream versions. However, I thought that we would probably want to do this in a separate PR, to minimize the size of this change.
1 parent ba87a15 commit 3defe3d

File tree

79 files changed

+642
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+642
-627
lines changed

Cargo.lock

Lines changed: 253 additions & 291 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,5 @@ debug = false
6363

6464
[patch.crates-io]
6565
webpki = { git = "https://github.com/linkerd/webpki", branch = "cert-dns-names-0.21", rev = "b2c3bb3" }
66-
# TODO(eliza): when the Tokio 0.3 versions of our various dependencies are
67-
# published, remove these patches...
68-
tower = { version = "0.4", git = "https://github.com/tower-rs/tower", rev = "450fa3d2be2b43850ceb125009d636d1d8629ad7" }
69-
hyper = { git = "https://github.com/hyperium/hyper", rev = "d6aadb830072959497f414c01bcdba4c8e681088" }
70-
# this isn't pinned to a rev because it needs to be consistent with Hyper's git
71-
# dep (which is not pinned).
72-
h2 = { git = "https://github.com/hyperium/h2" }
73-
# this isn't pinned to a rev because it needs to be consistent with Hyper's git
74-
# dep (which is `branch = "master"`).
75-
http-body = { git = "https://github.com/hyperium/http-body", branch = "master" }
76-
tokio-rustls = { git = "https://github.com/tokio-rs/tls", rev = "e6ef54641b911cfcf23b77a8c4826ae0f8e9870e" }
77-
tonic = { git = "https://github.com/hawkw/tonic", branch = "eliza/tokio-0.3" }
78-
tonic-build = { git = "https://github.com/hawkw/tonic", branch = "eliza/tokio-0.3" }
79-
prost = { git = "https://github.com/danburkert/prost" }
80-
prost-build = { git = "https://github.com/danburkert/prost" }
81-
prost-types = { git = "https://github.com/danburkert/prost" }
66+
tonic = { git = "https://github.com/hyperium/tonic" }
67+
tonic-build = { git = "https://github.com/hyperium/tonic" }

hyper-balance/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ publish = false
99
[dependencies]
1010
futures = "0.3"
1111
http = "0.2"
12-
hyper = "0.14.0-dev"
12+
hyper = "0.14.2"
1313
pin-project = "0.4"
14-
tower = { version = "0.4", default-features = false, features = ["load"]}
15-
tokio = { version = "0.3", features = ["macros"]}
14+
tower = { version = "0.4.1", default-features = false, features = ["load"]}
15+
tokio = { version = "1", features = ["macros"]}
1616

1717
[dev-dependencies]
18-
tokio-test = "0.3"
18+
tokio-test = "0.4"

linkerd/app/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ linkerd2-app-core = { path = "./core" }
2222
linkerd2-app-gateway = { path = "./gateway" }
2323
linkerd2-app-inbound = { path = "./inbound" }
2424
linkerd2-app-outbound = { path = "./outbound" }
25+
linkerd2-channel = { path = "../channel" }
2526
linkerd2-opencensus = { path = "../opencensus" }
2627
linkerd2-error = { path = "../error" }
2728
regex = "1.0.0"
28-
tokio = { version = "0.3", features = ["rt"] }
29+
tokio = { version = "1", features = ["rt"] }
2930
tonic = { version = "0.3", default-features = false, features = ["prost"] }
3031
tower = "0.4"
3132
tracing = "0.1.22"

linkerd/app/core/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ independently of the inbound and outbound proxy logic.
1616
mock-orig-dst = ["linkerd2-proxy-transport/mock-orig-dst"]
1717

1818
[dependencies]
19-
bytes = "0.6"
19+
bytes = "1"
2020
http = "0.2"
2121
http-body = "0.4"
22-
hyper = "0.14.0-dev"
22+
hyper = { version = "0.14.2", features = ["http1", "http2"] }
2323
futures = "0.3"
2424
indexmap = "1.0"
2525
ipnet = "2.0"
@@ -42,7 +42,7 @@ linkerd2-metrics = { path = "../../metrics" }
4242
linkerd2-transport-header = { path = "../../transport-header" }
4343
linkerd2-opencensus = { path = "../../opencensus" }
4444
linkerd2-proxy-core = { path = "../../proxy/core" }
45-
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", tag = "v0.1.16" }
45+
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", branch = "ver/tonic-git" }
4646
linkerd2-proxy-api-resolve = { path = "../../proxy/api-resolve" }
4747
linkerd2-proxy-discover = { path = "../../proxy/discover" }
4848
linkerd2-proxy-identity = { path = "../../proxy/identity" }
@@ -62,7 +62,7 @@ linkerd2-stack-metrics = { path = "../../stack/metrics" }
6262
linkerd2-stack-tracing = { path = "../../stack/tracing" }
6363
linkerd2-trace-context = { path = "../../trace-context" }
6464
regex = "1.0.0"
65-
tokio = { version = "0.3", features = ["macros", "sync", "parking_lot"]}
65+
tokio = { version = "1", features = ["macros", "sync", "parking_lot"]}
6666
tokio-timer = "0.2"
6767
tonic = { version = "0.3", default-features = false, features = ["prost"] }
6868
tracing = "0.1.22"
@@ -86,5 +86,5 @@ libc = "0.2"
8686
procinfo = "0.4.2"
8787

8888
[dev-dependencies]
89-
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", tag = "v0.1.16", features = ["arbitrary"] }
90-
prost-types = "0.6.0"
89+
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", branch = "ver/tonic-git", features = ["arbitrary"] }
90+
prost-types = "0.7.0"

linkerd/app/gateway/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ indexmap = "1.0"
1313
linkerd2-app-core = { path = "../core" }
1414
linkerd2-app-inbound = { path = "../inbound" }
1515
linkerd2-app-outbound = { path = "../outbound" }
16-
tower = { version = "0.4", default-features = false }
16+
tower = { version = "0.4.1", default-features = false }
1717
tracing = "0.1.22"
1818

1919
[dev-dependencies]
20-
tokio = { version = "0.3", features = ["rt", "macros"] }
21-
tokio-test = "0.3"
22-
tower = { version = "0.4", default-features = false, features = ["util"] }
23-
tower-test = "0.3"
20+
tokio = { version = "1", features = ["rt", "macros"] }
21+
tokio-test = "0.4"
22+
tower = { version = "0.4.1", default-features = false, features = ["util"] }
23+
tower-test = "0.4"
2424
linkerd2-app-test = { path = "../test" }

linkerd/app/inbound/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Configures and runs the inbound proxy
1010
"""
1111

1212
[dependencies]
13-
bytes = "0.6"
13+
bytes = "1"
1414
http = "0.2"
1515
futures = { version = "0.3" }
1616
indexmap = "1.0"
1717
linkerd2-app-core = { path = "../core" }
18-
tokio = { version = "0.3", features = ["sync"] }
18+
tokio = { version = "1", features = ["sync"] }
1919
tracing = "0.1.22"
2020

2121
[dependencies.tower]

linkerd/app/inbound/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn tcp_connect<T: Into<u16>>(
6969
.push_map_target(|t: T| ([127, 0, 0, 1], t.into()))
7070
// Limits the time we wait for a connection to be established.
7171
.push_timeout(config.timeout)
72+
.push(svc::stack::BoxFuture::layer())
7273
.into_inner()
7374
}
7475

linkerd/app/integration/Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ a dedicated crate to help the compiler cache dependencies properly.
1515
[features]
1616
# Disable to skip certain tests that should not be run on CI.
1717
flaky_tests = []
18-
# Enable to run tests for functionality that hasn't been ported to Tokio 0.2
19-
nyi = []
2018

2119
[dependencies]
22-
bytes = "0.6"
20+
bytes = "1"
2321
futures = "0.3"
2422
h2 = "0.3"
2523
http = "0.2"
2624
http-body = "0.4"
27-
hyper = "0.14.0-dev"
25+
hyper = { version = "0.14.2", features = ["http1", "http2", "stream", "client", "server"] }
26+
linkerd2-channel = { path = "../../channel" }
2827
linkerd2-app = { path = "..", features = ["mock-orig-dst"] }
2928
linkerd2-app-core = { path = "../core", features = ["mock-orig-dst"] }
3029
linkerd2-metrics = { path = "../../metrics", features = ["test_util"] }
31-
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", tag = "v0.1.16", features = ["arbitrary"] }
30+
linkerd2-proxy-api = { git = "https://github.com/linkerd/linkerd2-proxy-api", branch = "ver/tonic-git", features = ["arbitrary"] }
3231
linkerd2-app-test = { path = "../test" }
3332
regex = "0.1"
3433
socket2 = "0.3.12"
35-
rustls = "0.18"
36-
tokio = { version = "0.3", features = ["io-util", "net", "rt", "macros"]}
37-
tokio-rustls = "0.20"
38-
tower = { version = "0.4", default-features = false}
34+
rustls = "0.19"
35+
tokio = { version = "1", features = ["io-util", "net", "rt", "macros"]}
36+
tokio-rustls = "0.22"
37+
tower = { version = "0.4.1", default-features = false}
3938
tonic = { version = "0.3", default-features = false }
4039
tracing = "0.1.22"
4140
tracing-futures = { version = "0.2", features = ["std-future"] }

linkerd/app/integration/src/client.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::*;
2-
use hyper::body::Buf;
32
use linkerd2_app_core::proxy::http::trace;
43
use rustls::ClientConfig;
54
use std::io;
@@ -121,10 +120,7 @@ impl Client {
121120
res.status(),
122121
);
123122
let stream = res.into_parts().1;
124-
let mut body = hyper::body::aggregate(stream).await.expect("wait body");
125-
std::str::from_utf8(body.copy_to_bytes(body.remaining()).as_ref())
126-
.unwrap()
127-
.to_string()
123+
http_util::body_to_string(stream).await
128124
}
129125

130126
pub fn request(

0 commit comments

Comments
 (0)