Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Hyper 1.0 & Axum 0.7 #1670

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open

Conversation

alexrudy
Copy link

@alexrudy alexrudy commented Mar 31, 2024

Current Status: This is ready for CI & review!

This is a continuation of PR #1595 by @ikrivosheev.

TODO:

  • update imports to use -util crates (done in Update to hyper 1.0 and axum 0.7 #1595)
  • update AddrStream and AddrIncoming (done in Update to hyper 1.0 and axum 0.7 #1595)
  • fix hyper-timeout connector (done in Update to hyper 1.0 and axum 0.7 #1595)
  • use axum Request and Response in transport (via TowerToHyperService in Client)
  • change poll_trailers to use poll_frame. Still some work to do here about preserving data and trailers if poll_frame returns a frame type we aren't expecting.
  • Correctly handle data & trailer frames for server.
  • fix connect, Connect (no more hyper::client::service::Connect) (using hyper-util)
  • Get around "Implementation of From not general enough" compiler issue.
  • Correctly implement graceful shutdown (maybe based on hyper-util, but also not too hard to do independently, following axum's example.)
  • Pass through max_pending_accept_reset_streams (needs a release with PR #102 in hyper-util)
  • Correctly implement http2_only (needs PR #111 in hyper-util.
  • Figure out what to do about hyper_util ConnectError
  • Add socket2 dependency to support TCP SO_NODELAY and SO_KEEPALIVE
  • Compatibility of other tonic-* crates (e.g. tonic-web)
  • Examples
  • Check over Docs
  • Version Update

allan2 and others added 28 commits April 3, 2024 03:27
Some low-hanging import fixes
This commit is primarily converting Request and Response types within
the transport module to Axum 0.7 Request/Response. There is still more
to come to finish this conversion.

There are also small changes such as updating the hyper service builder
syntax.

Over the course of this commit,it was discovered that hyper-util is missing
`http2_max_pending_accept_reset_streams`.
Replaced with `tokio::net::TcpStream`.
Inspired by hyperium/hyper#2850
- use `Frame`.
- update `poll_data` to `poll_frame`
- remove `poll_trailers` in most places

I am not sure that a simple rename of `poll_data` to `poll_frame` is
right. I also left one instance of `poll_trailers` in
*tonic/src/codec/decode.rs*.
`is_connect` was deprecated when the higher-level client was removed
from hyper.
The corresponding comments are removed as well.
`http::Extensions::insert` requires `T: Clone` so we add it.
Provides adaptors between the Hyper-1.0 stable traits and traits needed by tonic and axum to send and recieve requests as a client.
@alexrudy alexrudy marked this pull request as ready for review April 3, 2024 03:41
@alexrudy
Copy link
Author

alexrudy commented Apr 3, 2024

I'd like to propose that this be reviewed as-is, and that we add follow-up issues for the remaining todos, which will all require PRs to land and then releases to happen for hyper and/or hyper-utils.

@karuna
Copy link

karuna commented Apr 6, 2024

works perfectly after cargo update

Phoenix500526 added a commit to Phoenix500526/Xline that referenced this pull request Apr 7, 2024
remove `--ignore` option when pr(when hyperium/tonic#1670) is merged.

Signed-off-by: Phoeniix Zhao <Phoenix500526@163.com>
Phoenix500526 added a commit to xline-kv/Xline that referenced this pull request Apr 8, 2024
remove `--ignore` option when pr(when hyperium/tonic#1670) is merged.

Signed-off-by: Phoeniix Zhao <Phoenix500526@163.com>
rustls-pemfile = { version = "1", optional = true }
tower-http = { version = "0.4", optional = true }
tokio-rustls = { version = "0.26.0", optional = true }
hyper-rustls = { version = "0.27.0", features = ["http2"], optional = true }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if there were feature flags to switch between the crypto backends.
Defaulting to aws-lc-rs pulls in a cmake, nasm requirement, impacts platform support, etc.
Trading that off for FIPS compliance isn't really needed in most cases.

Copy link

@aumetra aumetra Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which crypto provider tonic should default to is up to the maintainers, I guess.
But reqwest seems to be going the route of sticking to ring as the default crypto backend.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a good idea, but I don't think it should be included in this PR - this PR is already complicated as is. We can create an issue and work on multi-backend support separately once this lands.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely. I just felt like the comment fit best here for the time being since the PR isn't merged yet and I probably would have forgotten about it if I hadn't written it down

See rust-lang/cargo#10788 for the full issue.

When enabling a feature of a dependency, the syntax `tokio/rt` implicitly required a feature `tokio` to exist in 1.70 of cargo. By 1.77 this has been fixed. To work around this, we can use "weak feature dependencies" like `tokio?/rt` which enables the `rt` feature of tokio only if tokio is itself an enabled dependency. Also adding `dep:tokio` to the list of dependencies ensures that this is always true.

When the MSRV is upgraded again, we can probably remove the weak `?` and the `dep:tokio` in these cases.
transport uses tokio::select!
aws-lc-crypto doesn't seem to compile by defualt on windows.

Ideally, this should be a feature we toggle between.
It is only used by the TLS feature.
NOTE: These changed between prost-build 0.12.3 and 0.12.4, adding the top line ocmment which includes how they were generated.
axum 0.7 requires the `#[diagnostic]` attribute namespace on nightly.
This requires CMake.

Once again, a fast-follow should enable aws-lc-rs as a feature and the ability to switch between ring and aws-lc-rs
Found some places where links were not resolving correctly, this corrects them.
According to [hyperium#689](hyperium#689) streams should end after the first error. Therefore, when we find an error in the response step, discard the trailers so that the stream ends.
@tisonkun
Copy link
Contributor

cc @tottoto @LucioFranco can we get this patch a review? This should be one of the last blockers for many downstreams upgrade to hyper 1.0.

@tisonkun
Copy link
Contributor

@alexrudy FYI hyperium/hyper-util#102 is merged now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants