Skip to content

Conversation

benjaminp
Copy link
Contributor

After canceling a BlockingClientCall, the caller may not interact with it further. That means the call executor, a ThreadSafeThreadlessExecutor, will not execute any more tasks. There may still be tasks submitted to the call executor, though, until the underlying call completes. Some of these tasks (e.g., server messages available) may leak native resources unless executed. So, we convert the executor to a "direct" executor during cancellation in order to ensure all call tasks run.

Fixes #12355.

@benjaminp benjaminp changed the title stub: ensure BlockingClientCall tasks to run even after cancellation stub: ensure BlockingClientCall tasks run after cancellation Sep 22, 2025
After canceling a `BlockingClientCall`, the caller may not interact with it further. That means the call executor, a `ThreadSafeThreadlessExecutor`, will not execute any more tasks. There may still be tasks submitted to the call executor, though, until the underlying call completes. Some of these tasks (e.g., server messages available) may leak native resources unless executed. So, we convert the executor to a "direct" executor during cancellation in order to ensure all call tasks run.

Fixes grpc#12355.
@benjaminp benjaminp force-pushed the BlockingClientCall-leak branch from df3f751 to 6a6caf9 Compare September 22, 2025 16:15
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect we really want to drain the executor until the Listener.onClose() is delivered.

@benjaminp
Copy link
Contributor Author

The trouble is I don't think .cancel should be blocking.

@benjaminp
Copy link
Contributor Author

Another option might be to dump post-cancellation tasks on whatever executor would have been used for the call if we didn't force ThreadsafeThreadlessExecutor in.

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

Successfully merging this pull request may close these issues.

BlockingClientCall.cancel may orphan and leak pending reads
2 participants