When a task will be abort in tonic?
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## Bug Report
### Version
0.8.3
### Platform
Linux myname 5.15.0-82-generic #91-Ubuntu SMP Mon Aug 14 14:14:14 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
### Description
Hi, I encountered an issue while using Tonic, which might be caused by an aborted Tokio task. Let me briefly describe the problem I'm facing and I'm hoping to receive your response.
Here's the code I'm using, which is generated using the protocol:
```
pub mod server {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with MdsServer.
#[async_trait]
pub trait Mds: Send + Sync + 'static {
async fn look(
&self,
request: tonic::Request,
) -> Result, tonic::Status>;
}
}
```
This is the specific logic I've implemented for the `look` function.
```
#[tonic::async_trait]
impl server::Mds for MyMds {
async fn look(
&self, req: Request,
) -> Result, Status> {
mutex.lock().await; // This is a global lock
// Do something
info!("start functionA");
functionA().await.unwrap();
info!("end functionA");
}
}
```
However, I've noticed through logs that the service doesn't behave as expected. The logs show a pattern where the execution logic seems to repeat:
```
start functionA
end functionA
start functionA
end functionA
start functionA
end functionA
...
start functionA
start functionA
start functionA
...
```
It appears that the tasks are being discarded after reaching functionA().await, allowing new tasks to acquire the lock and execute the logic. I'm wondering under what circumstances Tonic might discard a task handling RPC server logic?
Contributor guide
Assessment
This issue has not been assessed yet.