You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
Please prominently document the task dropping behavior.
Maybe provide an option to log task drop occurrences.
Consider providing an option to NOT drop server tasks when a client cancels or times out, and
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.
The text was updated successfully, but these errors were encountered:
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
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:
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:
The text was updated successfully, but these errors were encountered: