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

Merged
merged 31 commits into from
Jun 12, 2024
Merged

Commits on Jun 12, 2024

  1. Upgrade to hyper 1 and http 1

    Upgrades only in Cargo.toml
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    20369f5 View commit details
    Browse the repository at this point in the history
  2. Convert from hyper::Body to http_body::BoxedBody

    When appropriate, we replace `hyper::Body` with `http_body::BoxedBody`, a good general purpose replacement for `hyper::Body`.
    
    Hyper does provide `hyper::body::Incoming`, but we cannot construct that, so anywhere we might need a body that we can construct (even most Service trait impls) we must use something like `http_body::BoxedBody`.
    
    When a service accepts `BoxedBody` and not `Incoming`, this indicates that the service is designed to run in places where it is not adjacent to hyper, for example, after routing (which is managed by Axum)
    
    Additionally, http >= 1 requires that extension types are `Clone`, so this bound has been added where appropriate.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    aaede1e View commit details
    Browse the repository at this point in the history
  3. Convert tonic::codec::decode to use http >= 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    alexrudy and ikrivosheev committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    ac2698d View commit details
    Browse the repository at this point in the history
  4. Convert tonic::transport::channel to use http >= 1 body types

    tonic::transport::channel previously used `hyper::Body` as the response body type. This type no longer exists in hyper >= 1, and so has been converted to a `BoxBody` provided by `http_body_util` designed for interoperability between http crates.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    3ef308c View commit details
    Browse the repository at this point in the history
  5. [tests] Convert tonic::codec::prost::tests to use http >= 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods. This also handles the return types which should now be wrapped in `Frame` when appropriate.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    8a24c79 View commit details
    Browse the repository at this point in the history
  6. Convert tonic::codec::encode to use http >= 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    e0f0f6c View commit details
    Browse the repository at this point in the history
  7. [tests] Convert tonic::service::interceptor::tests to use http >= 1 b…

    …ody types
    
    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods. This also handles the return types which should now be wrapped in `Frame` when appropriate.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    51cf7dc View commit details
    Browse the repository at this point in the history
  8. Convert tonic::transport to use http >= 1 body types

    Here, we must update some body types which are no longer valid. (A) BoxBody no longer has an `empty` method, instead we provide a helper in `tonic::body` for creating an empty boxed body via `http_body_util`. As well, `hyper::Body` is no longer a type, and instead, `hyper::Incoming` is used when directly recieving a Request from hyper, and `BoxBody` is used when the request may have passed through an axum router. In tonic, we prefer `BoxBody` as it allows for services to be used downstream from other components which enforce a specific body type (e.g. Axum), at the cost of making Body streaming opaque.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    4bf003b View commit details
    Browse the repository at this point in the history
  9. Convert tonic::transport::server::recover_error to use http >= 1 body…

    … types
    
    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Ludea <ludovicw35@hotmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    70abf84 View commit details
    Browse the repository at this point in the history
  10. Convert h2c examples to use http >= 1 body types

    In h2c, when a service is receiving from hyper, it has to accept a `hyper::body::Incoming` in hyper >= 1.
    
    Additionally, response bodies must be built from `http_body_util` combinators and become BoxBody objects.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    c5d0d13 View commit details
    Browse the repository at this point in the history
  11. [tests] Convert MergeTrailers body wrapper in interop server

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    c3ce3b3 View commit details
    Browse the repository at this point in the history
  12. [tests] Convert compression tests to use hyper 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    f2f7870 View commit details
    Browse the repository at this point in the history
  13. [tests] Convert complex_tower_middleware Body for hyper 1

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    829eb3b View commit details
    Browse the repository at this point in the history
  14. [tests] Convert integration_tests::origin to use http >= 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    55f9edb View commit details
    Browse the repository at this point in the history
  15. Convert tonic-web to use http >= 1 body types

    The Body trait has changed (removed `poll_data` and `poll_trailers`, they are now combined in `poll_frame`) and so the codec must be re-written to merge those two methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    26e640e View commit details
    Browse the repository at this point in the history
  16. Adapt for hyper-specific IO traits

    hyper >= 1 provides its own I/O traits (Read & Write) instead of relying on the equivalent traits from `tokio`. Then, `hyper-util` provides adaptor structs to wrap `tokio` I/O objects and implement the hyper equivalents. Therefore, we update the appropriate bounds to use the hyper traits, and update the I/O objects so that they are wrapped in the tokio to hyper adaptor.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    0e903cb View commit details
    Browse the repository at this point in the history
  17. Upgrade axum to 0.7

    Axum must be >= 0.7 to support hyper >= 1
    
    Doing this also involves changing the Body type used. Since hyper >= 1 does not provide a generic body type, Axum and tonic both use `BoxBody` to provide a pointer to a Body.
    
    This changes the trait bounds required for methods which accept additional Serivces to be run alongside the primary GRPC service, since those will be routed with Axum, and therefore must accept a BoxBody.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    e1e1ffe View commit details
    Browse the repository at this point in the history
  18. Convert service connector for hyper-1.0

    Hyper >= 1 no longer includes automatic http2/http1 combined connections, and so we must swtich to the `http2::Builder` type (this is okay, we set http2_only(true) anyhow).
    
    As well, hyper >= 1 is generic over executors and does not directly depend on tokio. Since http2 connections can be multiplexed, they require some additional background task to handle sending and receiving requests. Additionally, these background tasks do not natively implement `tower::Service` since hyper >= 1 does not depend on `tower`.
    
    Therefore, we re-implement the `SendRequest` task as a tower::Service, so that it can be used within `Connection`, which expects to operate on a tower::Service to serve connections.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    7a5d95c View commit details
    Browse the repository at this point in the history
  19. Convert hyper::Client to hyper_util::legacy::Client

    `hyper::Client` has been moved to `hyper_util::legacy::Client` in version 1.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    3 people committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    ef542bc View commit details
    Browse the repository at this point in the history
  20. Identify and propogate connect errors

    hyper::Error no longer provides information about Connect errors, especially since hyper_util now contains the connection implementation, it does not provide a separate error type.
    
    Instead, we create an internal Error type which is used in our own connectors, and then checked when figuring out what the gRPC status should be.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    9c6b63a View commit details
    Browse the repository at this point in the history
  21. Remove hyper::server::conn::AddrStream

    hyper >= 1 has deprecated all of `hyper::server`, including `AddrStream`
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    Co-authored-by: Allan Zhang <allanzhang7@gmail.com>
    
    Replace hyper::server::Accept
    
    hyper::server is deprectaed. Instead, we implement our own TCP-incoming based on the now removed hyper::server::Accept.
    
    In order to set `TCP_KEEPALIVE` we require the socket2 crate, since this option is not exposed in the standard library’s API. The implementaiton is inspired by that of hyper v0.14
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    39e9d57 View commit details
    Browse the repository at this point in the history
  22. [examples] In h2c, replace hyper::Server with an accept loop

    hyper::Server is deprecated, with no current common replacement. Instead of implementing (or using tonic’s new) full server in here, we write a simple accept loop, which is sufficient to demonstrate the functionality of h2c.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    ca9a859 View commit details
    Browse the repository at this point in the history
  23. Upgrade tls dependencies

    hyper-rustls requires version 0.27.0 to support hyper >= 1, bringing a few other tls bumps along. Importantly, we add the “ring” and “tls12” features to use ring as the crypto backend, consistent with previous versions of tonic. A future version of tonic might support selecting backends via features.
    
    Co-authored-by: Ivan Krivosheev <py.krivosheev@gmail.com>
    alexrudy and ikrivosheev committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    32c9183 View commit details
    Browse the repository at this point in the history
  24. Combine trailers when streaming decode body

    We aren't sure if multiple trailers should even be legal, but if we get multiple trailers in an HTTP body stream, we'll combine them all, to preserve their data.
    
    Alternatively we'd have to pick the first or last trailers, and that might lose information.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    ed74e45 View commit details
    Browse the repository at this point in the history
  25. Tweak imports in transport example

    Example used `empty_body()`, which is now fully qualified as `tonic::body::empty_body()` to make clear that this is a tonic helper method for creating an empty BoxBody.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    855ec61 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    bd9de54 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    deab62b View commit details
    Browse the repository at this point in the history
  28. tonic-web: Merge subsequent trailer frames

    Ideally, a body should only return a single trailer frame. If multiple trailers are returned, merge them together.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    39f9f11 View commit details
    Browse the repository at this point in the history
  29. Comment in tonic::status::find_status_in_source_chain

    Comment mentions why we choose “Unavailable” for connection errors
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    791b138 View commit details
    Browse the repository at this point in the history
  30. Make TowerToHyperService crate-private

    This also requires vendoring it in the rustls example, which doesn’t use a server type.
    
    Making the type crate-private means we can delete some unused methods.
    alexrudy committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    8345dfe View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    68a5bbd View commit details
    Browse the repository at this point in the history