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

"Service was not ready: transport error" when making gRPC request. #2144

Open
boxme opened this issue Jan 13, 2025 · 2 comments
Open

"Service was not ready: transport error" when making gRPC request. #2144

boxme opened this issue Jan 13, 2025 · 2 comments

Comments

@boxme
Copy link

boxme commented Jan 13, 2025

Bug Report

Encounter "Service was not ready: transport error" when making gRPC requests on from a client. The client was cloned before each request.

Version

tonic = "0.12"

Description

A grpc client was created at startup before serving my backend APIs. There are a bunch of setups but the following highlighted the gRPC client setup:

pub struct Router {
    pub gprc_client: Arc<MygRpcClient>,
    ....
}

fn main() {
    let router = {
        let rt = tokio::runtime::Builder::new_multi_thread()
            .enable_all()
            .worker_threads(config.thread_config.total_thread_count)
            .build()
            .unwrap();

        rt.block_on(async move {
            let client = get_grpc_client("https://rtse-api-service.rtse.svc.cluster.local/").await.unwrap()
            let router = Router {
                gprc_client: Arc::new(client),
            };

            router
        })
    };

    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .worker_threads(5)
        .build()
        .unwrap();

   rt.block_on(run_api(router)).unwrap();
}

async fn get_grpc_client(url: String) -> Option<MygRpcClient> {
    let channel = Endpoint::from_shared(url);
    match channel {
        Ok(endpoint) => Some(
            MyServiceClient::new(endpoint.connect_lazy())
                .accept_compressed(tonic::codec::CompressionEncoding::Zstd)
                .send_compressed(tonic::codec::CompressionEncoding::Zstd),
        ),
        Err(_) => None,
    }
}

For each request I am cloning the client in order to handle concurrent request:

pub async fn handle_request(&self) {
    ...
    let gprc_client = (*self.gprc_client).clone();
    let request =  Request::new(GetRequest {
        param_a: ...,
        param_b: ...,
    });

    let result = gprc_client.handle_grpc_request(request).await;

    match result {
        Ok(result) =>  {
            ...
        },
        Err(err) => {
            let error_code = err.code();
            let error_message = err.message();

            // Got Error: Unknown error: Service was not ready : transport error
            log::error!("Got Error: {error_code} : {error_message}");
        }
    }
}

Could someone help me understand this error better? Thanks!

@LucioFranco
Copy link
Member

try calling grpc_client.ready().await;

@dummyhs12341234
Copy link

@LucioFranco I ran into a similar issue but ready is not an available method. Any other ideas?

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

No branches or pull requests

3 participants