Skip to content

feat(transport): add support for uds, unix domain socket #2218

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

Merged

Conversation

adamcavendish
Copy link
Contributor

Commit Message

Previously the uds support lives as an example in the example/src/uds folder. Endpoint is refactored to support multiple endpoint types, including Uri and Uds.

The supported unix domain socket URI follows RFC-3986 which is aligned with the gRPC naming convention.

  • unix:relative_path
  • unix:///absolute_path

References:

Motivation

  • Previously required custom connectors and explicit tower dependencies for UDS. Uds Connector Example

  • Users can now use the same connect() API for both TCP and UDS:

    let client = GreeterClient::connect("unix:///tmp/tonic/helloworld").await?;

Solution

  1. To implement the feature, Endpoint is refactored support multiple endpoint types:

    +#[derive(Clone, PartialEq, Eq, Hash)]
    +pub(crate) enum EndpointType {
    +    Uri(Uri),
    +    Uds(String),
    +}
    +
     /// Channel builder.
     ///
     /// This struct is used to build and configure HTTP/2 channels.
     #[derive(Clone)]
     pub struct Endpoint {
    -    pub(crate) uri: Uri,
    +    pub(crate) uri: EndpointType,
    +    fallback_uri: Uri,
  2. To satisfy the backward compatibility of Endpoint::uri() method, the fallback_uri attribute is added and returned when user working with uds mode so the method will still be able to return a &Uri.

         pub fn uri(&self) -> &Uri {
    -        &self.uri
    +        match &self.uri {
    +            EndpointType::Uri(uri) => uri,
    +            EndpointType::Uds(_) => &self.fallback_uri,
    +        }
         }

adamcavendish pushed a commit to adamcavendish/tonic that referenced this pull request Mar 12, 2025
Previously the uds support lives as an example in the `example/src/uds` folder.
Endpoint is refactored to support multiple endpoint types, including Uri and
Uds.

The supported unix domain socket URI follows RFC-3986 which is aligned with
the gRPC naming convention.
- unix:relative_path
- unix:///absolute_path

References:
- https://datatracker.ietf.org/doc/html/rfc3986
- https://github.com/grpc/grpc/blob/master/doc/naming.md
@adamcavendish adamcavendish force-pushed the feature/endpoint-uds-support branch from 2e43f17 to b57b964 Compare March 12, 2025 10:08
@adamcavendish adamcavendish changed the title feat: add support for uds, unix domain socket feat(transport): add support for uds, unix domain socket (#2218) Mar 12, 2025
@adamcavendish
Copy link
Contributor Author

@tottoto @LucioFranco Please help review when you are available. Thanks!

@adamcavendish
Copy link
Contributor Author

@tottoto @LucioFranco Kindly ping here to get some reviews and CI running. Thanks!

@@ -0,0 +1,59 @@
use std::future::Future;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The UdsConnector is the core part of this pull request.

adamcavendish added a commit to adamcavendish/tonic that referenced this pull request Mar 24, 2025
Previously the uds support lives as an example in the `example/src/uds` folder.
Endpoint is refactored to support multiple endpoint types, including Uri and
Uds.

The supported unix domain socket URI follows RFC-3986 which is aligned with
the gRPC naming convention.
- unix:relative_path
- unix:///absolute_path

References:
- https://datatracker.ietf.org/doc/html/rfc3986
- https://github.com/grpc/grpc/blob/master/doc/naming.md
@adamcavendish adamcavendish force-pushed the feature/endpoint-uds-support branch from b57b964 to dc7ec67 Compare March 24, 2025 03:02
@adamcavendish adamcavendish changed the title feat(transport): add support for uds, unix domain socket (#2218) feat(transport): add support for uds, unix domain socket Mar 24, 2025
Previously the uds support lives as an example in the `example/src/uds` folder.
Endpoint is refactored to support multiple endpoint types, including Uri and
Uds.

The supported unix domain socket URI follows RFC-3986 which is aligned with
the gRPC naming convention.
- unix:relative_path
- unix:///absolute_path

References:
- https://datatracker.ietf.org/doc/html/rfc3986
- https://github.com/grpc/grpc/blob/master/doc/naming.md
@adamcavendish adamcavendish force-pushed the feature/endpoint-uds-support branch from dc7ec67 to c7d89d6 Compare March 25, 2025 01:48
@adamcavendish
Copy link
Contributor Author

adamcavendish commented Mar 25, 2025

I have rebased to the latest master. @tottoto @LucioFranco would you like to have some discussions?

Comment on lines +156 to +158
let s = str::from_utf8(&s.into())
.map_err(|e| Error::new_invalid_uri().with(e))?
.to_string();
Copy link
Member

Choose a reason for hiding this comment

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

This is unfortunate, this removes the ability to use the shared attributes because you allocate anyways. Can we just check the bytes instead of converting it to a string?

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Overall LGTM a few nits and CI to fix

@LucioFranco
Copy link
Member

I will push some changes to get this over the finish line since I have some time right now.

@LucioFranco LucioFranco added this pull request to the merge queue Mar 25, 2025
Merged via the queue into hyperium:master with commit 7b2984c Mar 25, 2025
18 checks passed
@adamcavendish adamcavendish deleted the feature/endpoint-uds-support branch March 26, 2025 00:39
@adamcavendish
Copy link
Contributor Author

@LucioFranco Thanks for your revisions on making it work on Windows platforms. I really appreciated it.

github-merge-queue bot pushed a commit that referenced this pull request May 6, 2025
* Add From<T> for Response<T> (#1064)

Co-authored-by: tottoto <[email protected]>

* chore: Add getrandom and wasi crate to cargo-deny skip config (#2169)

* chore(examples): Update to rand 0.9 (#2168)

* chore(interop): Replace repeat and take with repeat_n (#2170)

* Update LICENSE (#2167)

* chore(transport): Update url to http crate document (#2173)

* chore: Refactor redundant pattern match (#2174)

* chore(transport): Remove redundant type reconstruct (#2176)

* chore: Update to strum 0.27 (#2180)

* feat: optional `SSLKEYLOGFILE` support (#1539)

Add a `use_key_log` option to server and client TLS configs that -- when
set -- will enable rustls's `SSLKEYLOGFILE` handling.

This is helpful when you want to intercept TLS traffic for debugging and
is generally supported by many libraries and browsers. Also see:
https://wiki.wireshark.org/TLS#using-the-pre-master-secret

* chore: Remove html_root_url (#2184)

* chore: Remove unused mutability (#2183)

* chore: Update generated code (#2222)

* chore: Update cargo-deny config (#2210)

* chore: Add rustix and linux-raw-sys crate to cargo-deny skip config

* chore: Ignore RUSTSEC-2024-0436

* Remove unnecessary mut (#2219)

* remove unnecessary mut

* remove unnecessary mut for health_reporter

---------

Co-authored-by: tottoto <[email protected]>

* chore: fix some comments (#2224)

Signed-off-by: jimmycathy <[email protected]>
Co-authored-by: tottoto <[email protected]>

* feat: Allow convert i32 to Code in const context (#2195)

* chore: Disable unused tower feature (#2196)

* chore(router): Remove unnecessary body type converting (#2214)

* chore(server): Use standard library pin macro (#2212)

* chore(build): Use idiomatic api (#2211)

* feat(tonic): Exclude benches-disabled to remove Apache-2.0 resource (#2204)

* chore(ci): Add concurrency group to cancel old ci (#2202)

* chore(test): Use library crate in test (#2201)

* chore: Remove unused rand crate from dev-dependencies (#2198)

* chore: Remove documentation config in manifest (#2193)

* chore(test): Remove unnecessary macro_use (#2200)

* feat: Add proto header to generated code (#2205)

* chore(router): Use upstream poll_ready to implement service (#2215)

* feat(router): Use infallible as error type (#2232)

* chore: Remove unnecessary license file from private crate (#2203)

* chore: update changelog to point to releases (#2235)

* chore: fix changelog header

* chore(server): Remove import sleep and pending function (#2234)

* chore(server): Refactor default http2 keepalive timeout config (#2213)

* chore: Remove unnecessary docs.rs config (#2223)

* feat(transport): add support for uds, unix domain socket (#2218)

* feat(transport): add support for uds, unix domain socket (#2218)

Previously the uds support lives as an example in the `example/src/uds` folder.
Endpoint is refactored to support multiple endpoint types, including Uri and
Uds.

The supported unix domain socket URI follows RFC-3986 which is aligned with
the gRPC naming convention.
- unix:relative_path
- unix:///absolute_path

References:
- https://datatracker.ietf.org/doc/html/rfc3986
- https://github.com/grpc/grpc/blob/master/doc/naming.md

* fix feature flag error

* fix windows build

* fix windows build 2

* fix windows build 3

* fix windows build 4

* fix windows build 5

---------

Co-authored-by: Lucio Franco <[email protected]>

* Handle stream error correctly (#2199)

Co-authored-by: Lucio Franco <[email protected]>

* chore: Remove resolved cargo-deny config (#2230)

* Create place for grpc crate and initial contents (#2192)

* Create place for grpc crate and initial contents

* Cargo.toml fixes

* clippy

* clippy 2

* 3

* grpc-web: relax bounds for inner service's response body (#2245)

* grpc-web: relax bounds for inner service's response body

* address feedback

* chore(test): Allow clippy::doc_overindented_list_items lint in generated code (#2246)

* chore(test): Update to rand 0.9 (#2236)

* chore(router): Remove unnecessary type converting (#2237)

* chore(ci): Update to nightly-2025-03-27 on udeps ci (#2242)

* chore(codegen): Update to protox 0.8 (#2254)

* chore(ci): Remove deny job (#2255)

Removing the deny ci job it has become more of a pain to manage than
actually helpful.

* feat: preserve request user-agent (#2250)

Co-authored-by: Lucio Franco <[email protected]>

* feat(server): Add method to get local addr to TcpIncoming (#2233)

* feat: expose Status as a Response extension (#2145)

Co-authored-by: Lucio Franco <[email protected]>

* chore(server): Remove unnecessary await service ready (#2258)

* chore: Use symbolic link for license file (#2241)

* chore: Use inline format argument (#2260)

* chore: Add `flake.nix` (#2261)

* chore: Fix interop test certs (#2262)

* chore: Fix interop test certs

* fix bash script:

* fix: tls config overwrite in endpoint (#2252)

* fix: tls config overwrite in endpoint

PR #1866 fixed the breaking change introduced in #1731, but
resets the TLS config without checking if `tls` is set. This
patch resolves the regression and restores expected behaviour.

* fix: cargo fmt whitespace check

---------

Co-authored-by: vigneshwar.sm <[email protected]>
Co-authored-by: Lucio Franco <[email protected]>

* chore(tonic-bench): Fix failing bench (#2207)

Co-authored-by: Lucio Franco <[email protected]>

* feat: expose creation of HealthService and HealthReporter (#2251)

* Expose creation of HealthService and HealthReporter

* add default impl for HealthReporter

* [spr] initial version (#2264)

Created using spr 1.3.6-beta.1

* Revert "[spr] initial version (#2264)" (#2265)

* chore: Prepare `v0.13.1` release



Reviewers: 

Pull Request: #2266

---------

Signed-off-by: jimmycathy <[email protected]>
Co-authored-by: Amr Hassan <[email protected]>
Co-authored-by: tottoto <[email protected]>
Co-authored-by: Maxim Evtush <[email protected]>
Co-authored-by: Marco Neumann <[email protected]>
Co-authored-by: DAKAI, TZOU <[email protected]>
Co-authored-by: jimmycathy <[email protected]>
Co-authored-by: Adam Basfop Cavendish <[email protected]>
Co-authored-by: Jakub Łabor <[email protected]>
Co-authored-by: Doug Fawley <[email protected]>
Co-authored-by: Brandon Williams <[email protected]>
Co-authored-by: Darren Bolduc <[email protected]>
Co-authored-by: Ferenc Tamás <[email protected]>
Co-authored-by: Vigneshwar S <[email protected]>
Co-authored-by: vigneshwar.sm <[email protected]>
Co-authored-by: Rafael RL <[email protected]>
Co-authored-by: Leon Hartley <[email protected]>
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.

2 participants