"Service was not ready: transport error" when cloning client
Bug Report
Cloning client as per recommendation: https://github.com/hyperium/tonic/pull/328/files but getting "Service was not ready: transport error" when cloning client
Version
tonic = "0.6"
Platform
ubuntu 18
Description
I have the following structure:
pub struct AuthenticatorImpl {
workload_api_client: SpiffeWorkloadApiClient<Channel>,
}
I am creating the client like this:
let path = agent_socket_path.to_string();
// Port is not important here, since we connect to uds.
let channel = Endpoint::try_from("http://[::]:50051")
.unwrap()
.connect_with_connector(service_fn(move |_: Uri| {
// Connect to a Uds socket
UnixStream::connect(path.clone())
}))
.await
.unwrap();
SpiffeWorkloadApiClient::new(channel)
However, running this, will fail:
let mut workload_api_client = self.workload_api_client.clone();
// Response contains claim which can be used for authorization.
let response = workload_api_client.validate_jwtsvid(request).await.unwrap().into_inner();
With the following error message: Status { code: Unknown, message: "Service was not ready: transport error", source: None }
The workaround that works for me is:
let path = agent_socket_path.to_string();
// Port is not important here, since we connect to uds.
let channel = Endpoint::try_from("http://[::]:50051")
.unwrap()
.connect_with_connector(service_fn(move |_: Uri| {
// Connect to a Uds socket
UnixStream::connect(path.clone())
}))
.await
.unwrap();
let mut workload_api_client = piffeWorkloadApiClient::new(channel);
But ideally, I would rather just clone the client. Thank you!
Hi, I am looking into this but I am having trouble recreating the issue you're having. Would it be possible for you to create a small repro example I can run on my computer to see what the issue is?
Thanks for looking! I'll try to small repro for you today.
For anyone wondering, I ran into the same issues while testing a gRPC implementation with tokio. Reason was that tokio creates a new runtime on every test. I was referencing the gRPC service from a global context, but gRPC depends on its original runtime in which it was created. So you can either spawn a new gRPC service for every test or use some of the described workarounds in this issue
Thanks yes, generally speaking you should create a client per test.