tonic icon indicating copy to clipboard operation
tonic copied to clipboard

"Service was not ready: transport error" when cloning client

Open huguesBouvier opened this issue 3 years ago • 2 comments

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!

huguesBouvier avatar Mar 18 '22 17:03 huguesBouvier

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?

LucioFranco avatar Mar 31 '22 18:03 LucioFranco

Thanks for looking! I'll try to small repro for you today.

huguesBouvier avatar Apr 01 '22 22:04 huguesBouvier

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

n-0 avatar Nov 14 '22 09:11 n-0

Thanks yes, generally speaking you should create a client per test.

LucioFranco avatar Nov 14 '22 15:11 LucioFranco