From 2d9ef18962df04d7216dc2d3c6713fe70dfa2791 Mon Sep 17 00:00:00 2001 From: Yu Li Date: Thu, 16 Nov 2023 18:32:28 +0800 Subject: [PATCH] chore(volo-http): bump to hyper 1.0.0 Note that `hyper` v1.0.0-rc4 replaces IO traits from `tokio` with its IO traits in `hyper::rt`. To solve the building problem, we can introduce `TokioIo` from `hyper-util` and wrap the `DefaultIncoming` by the `TokioIo`. Also, the `volo-grpc` uses `hyper` v0.14 with its auto-version (using both http1 and http2) and graceful shutdown, but the latest `hyper` and `hyper-util` cannot use the both features at the same time, so the version of `hyper` in `volo` has not been upgraded. Ref: - https://github.com/hyperium/hyper/commit/f9f65b7aa67fa3ec0267fe015945973726285bc2 - https://github.com/hyperium/hyper/pull/3013 - https://github.com/hyperium/hyper/issues/2862 Signed-off-by: Yu Li --- Cargo.lock | 197 +++++++++++++++++++++++++--------------- examples/Cargo.toml | 4 +- volo-http/Cargo.toml | 28 +++--- volo-http/src/lib.rs | 2 +- volo-http/src/server.rs | 10 +- 5 files changed, 150 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42f8eafa..89c7c974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,9 +261,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" +checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" dependencies = [ "clap_builder", "clap_derive", @@ -271,9 +271,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" +checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" dependencies = [ "anstream", "anstyle", @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ "humantime", "is-terminal", @@ -480,9 +480,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" dependencies = [ "libc", "windows-sys", @@ -490,9 +490,9 @@ dependencies = [ [[package]] name = "event-listener" -version = "3.0.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cec0252c2afff729ee6f00e903d479fba81784c8e2bd77447673471fdfaea1" +checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" dependencies = [ "concurrent-queue", "parking", @@ -516,8 +516,8 @@ dependencies = [ "anyhow", "async-stream", "bytes", - "http", - "hyper 1.0.0-rc.3", + "http 1.0.0", + "hyper 1.0.0", "lazy_static", "metainfo", "motore", @@ -739,17 +739,36 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" dependencies = [ "bytes", "fnv", "futures-core", "futures-sink", "futures-util", - "http", - "indexmap 1.9.3", + "http 0.2.11", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", + "indexmap 2.1.0", "slab", "tokio", "tokio-util", @@ -806,9 +825,20 @@ dependencies = [ [[package]] name = "http" -version = "0.2.9" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" dependencies = [ "bytes", "fnv", @@ -822,30 +852,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.11", "pin-project-lite", ] [[package]] name = "http-body" -version = "1.0.0-rc.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http", + "http 1.0.0", ] [[package]] name = "http-body-util" -version = "0.1.0-rc.2" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92445bc9cc14bfa0a3ce56817dc3b5bcc227a168781a356b702410789cec0d10" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http", - "http-body 1.0.0-rc.2", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -877,8 +907,8 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", + "h2 0.3.22", + "http 0.2.11", "http-body 0.4.5", "httparse", "httpdate", @@ -893,24 +923,21 @@ dependencies = [ [[package]] name = "hyper" -version = "1.0.0-rc.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75264b2003a3913f118d35c586e535293b3e22e41f074930762929d071e092" +checksum = "24590385be94998c5def4cf53d34edc5381144c805126f00efb954d986f9a7b2" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", - "h2", - "http", - "http-body 1.0.0-rc.2", + "h2 0.4.0", + "http 1.0.0", + "http-body 1.0.0", "httparse", "httpdate", "itoa", "pin-project-lite", "tokio", - "tracing", - "want", ] [[package]] @@ -920,7 +947,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", + "http 0.2.11", "hyper 0.14.27", "rustls", "tokio", @@ -939,6 +966,26 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca339002caeb0d159cc6e023dff48e199f081e42fa039895c7c6f38b37f2e9d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.0.0", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.58" @@ -1037,6 +1084,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -1582,16 +1638,16 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11f8b2436abeb9bc52c0899553592eecefc2c84156ddfc5fd99c5180145b8f2d" +checksum = "ee39fed526eaec777f393c14c0692bfe9a71ea18c357c9f29ba06ce796bbd751" dependencies = [ "anyhow", "dashmap", "faststr", "fxhash", "heck 0.4.1", - "itertools", + "itertools 0.11.0", "lazy_static", "normpath", "paste", @@ -1696,9 +1752,9 @@ dependencies = [ [[package]] name = "proptest" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", @@ -1708,7 +1764,7 @@ dependencies = [ "rand", "rand_chacha", "rand_xorshift", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", "rusty-fork", "tempfile", "unarray", @@ -1891,12 +1947,6 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "regex-syntax" version = "0.8.2" @@ -1914,8 +1964,8 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", + "h2 0.3.22", + "http 0.2.11", "http-body 0.4.5", "hyper 0.14.27", "hyper-rustls", @@ -1980,9 +2030,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" dependencies = [ "bitflags 2.4.1", "errno", @@ -2005,9 +2055,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ "base64 0.21.5", ] @@ -2238,9 +2288,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "socket2" @@ -2332,9 +2382,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" dependencies = [ "winapi-util", ] @@ -2396,9 +2446,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes", @@ -2425,9 +2475,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", @@ -2592,9 +2642,9 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ "log", "once_cell", @@ -2603,9 +2653,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "matchers", "nu-ansi-term", @@ -2773,7 +2823,7 @@ dependencies = [ "dirs", "git2", "heck 0.4.1", - "itertools", + "itertools 0.12.0", "lazy_static", "nom", "normpath", @@ -2800,7 +2850,7 @@ dependencies = [ "clap", "colored", "heck 0.4.1", - "itertools", + "itertools 0.12.0", "lazy_static", "log", "normpath", @@ -2841,9 +2891,9 @@ dependencies = [ "futures", "futures-util", "fxhash", - "h2", + "h2 0.3.22", "hex", - "http", + "http 0.2.11", "http-body 0.4.5", "hyper 0.14.27", "hyper-timeout", @@ -2870,9 +2920,10 @@ version = "0.0.0" dependencies = [ "bytes", "futures-util", - "http", + "http 1.0.0", "http-body-util", - "hyper 1.0.0-rc.3", + "hyper 1.0.0", + "hyper-util", "matchit", "mime", "motore", diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 06877f88..97118839 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -81,8 +81,8 @@ path = "src/http/http.rs" anyhow.workspace = true async-stream.workspace = true bytes.workspace = true -http.workspace = true -hyper = { version = "1.0.0-rc.3", features = ["server", "http1", "http2"] } +http = "1.0" +hyper = { version = "1.0", features = ["server", "http1", "http2"] } lazy_static.workspace = true metainfo.workspace = true motore.workspace = true diff --git a/volo-http/Cargo.toml b/volo-http/Cargo.toml index 0987660d..0b936cab 100644 --- a/volo-http/Cargo.toml +++ b/volo-http/Cargo.toml @@ -19,9 +19,22 @@ maintenance = { status = "actively-developed" } [dependencies] volo = { version = "0.8", path = "../volo" } -motore.workspace = true -hyper = { version = "=1.0.0-rc.3", features = ["server", "http1", "http2"] } +http = "1.0" +http-body-util = "0.1" +hyper = { version = "1.0", features = ["server", "http1", "http2"] } +hyper-util = { version = "0.1", features = ["tokio"] } + +bytes.workspace = true +futures-util.workspace = true +matchit.workspace = true +mime.workspace = true +motore.workspace = true +parking_lot.workspace = true +pin-project.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true tokio = { workspace = true, features = [ "time", "macros", @@ -29,18 +42,7 @@ tokio = { workspace = true, features = [ "signal", "parking_lot", ] } -http.workspace = true -http-body-util = "=0.1.0-rc.2" -matchit.workspace = true tracing.workspace = true -futures-util.workspace = true -pin-project.workspace = true -bytes.workspace = true -serde_json.workspace = true -thiserror.workspace = true -mime.workspace = true -serde.workspace = true -parking_lot.workspace = true [dev-dependencies] serde = { version = "1", features = ["derive"] } diff --git a/volo-http/src/lib.rs b/volo-http/src/lib.rs index e80f2c97..e91906c5 100644 --- a/volo-http/src/lib.rs +++ b/volo-http/src/lib.rs @@ -51,7 +51,7 @@ where type Future = impl Future>; - fn call(&mut self, req: Request) -> Self::Future { + fn call(&self, req: Request) -> Self::Future { let s = self.inner.clone(); let peer = self.peer.clone(); async move { diff --git a/volo-http/src/server.rs b/volo-http/src/server.rs index 95d33673..4f292dfc 100644 --- a/volo-http/src/server.rs +++ b/volo-http/src/server.rs @@ -8,6 +8,7 @@ use hyper::{ body::{Body, Incoming as BodyIncoming}, server::conn::http1, }; +use hyper_util::rt::TokioIo; use motore::BoxError; use tracing::{info, trace}; use volo::net::{incoming::Incoming, MakeIncoming}; @@ -60,12 +61,17 @@ where let mut watch = rx_inner.clone(); tokio::task::spawn(async move { let mut http_conn = http1::Builder::new() - .serve_connection(conn, MotoreService { peer, inner: s.app }); + .serve_connection( + TokioIo::new(conn), + MotoreService { peer, inner: s.app } + ); tokio::select! { _ = watch.changed() => { tracing::trace!("[VOLO] closing a pending connection"); // Graceful shutdown. - hyper::server::conn::http1::Connection::graceful_shutdown(Pin::new(&mut http_conn)); + hyper::server::conn::http1::Connection::graceful_shutdown( + Pin::new(&mut http_conn) + ); // Continue to poll this connection until shutdown can finish. let result = http_conn.await; if let Err(err) = result {