Using tonic inside async checkpoint #2094
Replies: 4 comments
-
this error panic and not throw o display any message. After some code analisys i found this. #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
let mut tasks = Vec::new();
let mut client: TokenClient<Channel> = TokenClient::connect("http://[::1]:50051").await?;
for i in 1..1000 {
let mut client = client.clone();
tasks.push(
tokio::spawn(async move {
println!("running");
send(client.clone()).await
})
);
}
// join_all(tasks).await;
Ok(())
} Without join_all(tasks).await the tonic client throw this error RESPONSE=Err(Status { code: Unknown, message: "Service was not ready: transport error", source: None }) And is the same in my plugin but without throwing any error message. i update my apollo router plugin doind waiting for rpc response a bit time and the code works. let mut client = TokenClient::new(channel);
match client.check_token(request).await {
Ok(_) => {
sleep(Duration::from_millis(20)).await;
Ok(ControlFlow::Continue(req))
}
Err(_) =>{
sleep(Duration::from_millis(20)).await;
failure_message(req.context, "Un authorized JWT".to_string(), StatusCode::UNAUTHORIZED)
},
} i would like to achieve this without sleep function. |
Beta Was this translation helpful? Give feedback.
-
seanmonstar/reqwest#541 i found this issue and solution. it a problem related to tokio clients... sth about threads. now the code works creating an static client lazy_static! {
static ref TONIC_CLIENT: AsyncOnce<Channel> = AsyncOnce::new(async {
Channel::from_static("http://[::1]:50051").connect().await.expect("Cnt connect to the chanel")
});
} let mut channel = TONIC_CLIENT.get().await;
let mut client = TokenClient::new(channel.clone()); Clone the Channel is easy and works well, without sleep or something more. |
Beta Was this translation helpful? Give feedback.
-
I don't think this is an issue relating to the router, so I'm going to convert this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Hello i'm triying to use a grcp client inside an async checkpoint, it works if i create the client for each request but doesnt work if the client is created on ::new method and passing it cloned.
Beta Was this translation helpful? Give feedback.
All reactions