grpc / grpc/grpc-rust

option to not abort server task if client request cancels or times out

Open
#1,624 2 comments 17 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

## Feature Request

### Motivation

When a client RPC times out, tonic aborts the server task that is servicing that request. This takes the form of an .await never returning control to my code.

This behavior is a surprise for the unwary. Consider:

```

some_async_call().await;

```

If the .await doesn't return control because the task is aborted by tonic (due to e.g. client timeout), then my logic leaks the acquired resource.

At [https://docs.rs/tokio/latest/tokio/task/index.html#cancellation](https://docs.rs/tokio/latest/tokio/task/index.html#cancellation) Tokio documents this behavior as "When tasks are shut down, it will stop running at whichever .await it has yielded at. All local variables are destroyed by running their destructor."

Because locals are destroyed, using RAII solves the resource management aspect of a blackholed .await.

In addition to using RAII in my logic, I am also spawning long-running operations to a separate task, so that if the client RPC times out, the dropped task will not take my task down.

### Proposal

Four requests:

1. Please prominently document the task dropping behavior.
2. Maybe provide an option to log task drop occurrences.
3. Consider providing an option to NOT drop server tasks when a client cancels or times out, and
4. Allow server logic to discover that the task has a pending cancellation due to client cancel or timeout (maybe via a RPC request context object) so the server logic can decide when and how to abandon its work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.