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

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

Open
smroid opened this issue Feb 6, 2024 · 0 comments
Open

Comments

@smroid
Copy link

smroid commented Feb 6, 2024

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:

  <acquire resource>
  some_async_call().await;
  <release resource>

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 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.
@smroid smroid changed the title option to NOT abort server task if client request cancels or times out option to not abort server task if client request cancels or times out Feb 6, 2024
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

1 participant