-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support non-static UDS client connection paths #1612
Comments
Update unix domain socket examples to show configurable paths. It demonstrates a way of configuring the UDS client using the ustr crate to meet the closure capture requirements of the connector service_fn. Fixes: hyperium#1611 Refs: hyperium#1612
I second this like let path = PathBuf::from("/tmp/tonic/helloworld");
let channel = Endpoint::try_from("http://[::]:50051")?
.connect_with_connector(service_fn(move |_: Uri| {
// Connect to a Uds socket
UnixStream::connect(path.clone())
}))
.await?; |
This no longer works on 0.12 version after this change: #1670 let path = PathBuf::from("/tmp/my.sock");
let channel = Endpoint::try_from("http://[::]:50051")?
.connect_with_connector(service_fn(move |_| async {
// Connect to a Uds socket
let io = TokioIo::new(UnixStream::connect(path.clone()).await?);
Ok::<_, std::io::Error>(io)
}))
.await?; gives error:
I wrote a custom ServiceFn (UdsConnector) that owns the path to work around, and I can upstream it here if tonic owners are open for it. |
ServiceFn must be re-usable, so the future returned can't borrow from the surrounding closure. This works: let path = PathBuf::from("/tmp/my.sock");
let channel = Endpoint::try_from("http://[::]:50051")?
.connect_with_connector(service_fn(move |_| {
let path = path.clone();
async move {
// Connect to a Uds socket
let io = TokioIo::new(UnixStream::connect(path).await?);
Ok::<_, std::io::Error>(io)
}
}))
.await?; |
This works. Thanks for the suggestion. |
Feature Request
Support non-static UDS client connection paths
Motivation
Currently the UDS client example is using a static path, I believe because of the ownership requirements of the service function closure:
tonic/examples/src/uds/client.rs
Lines 16 to 28 in c30cb78
It would be great if
tonic
and itshyperium
dependencies, as needed, took ownership of the specified path to avoid the user needing to vend a&'static str
.Related
The text was updated successfully, but these errors were encountered: