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

Fix gRPC client retry deadlock #2209

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Jul 26, 2023

Fixes #2206

I believe the problem is caused by a call's TCS being created without RunContinuationsAsynchronously. When the call is disposed under a lock, the TCS is completed, and continuations are run on the same thread, still holding the lock. That includes logic after the await here in RetryCall.

The simple fix would be to add that setting. Unfortunately, RunContinuationsAsynchronously can't be used here because it breaks Activity.

Instead, I moved disposing the active call outside of the lock. I think this fixes the deadlock, but I don't have repro to confirm.

Another idea I had, which isn't in this PR, is to place a Task.Yield() after the await in RetryCall. It forces the call's TCS to stop executing synchronously, _callTcs.TrySetResult(...) returns, the call's dispose finishes, and exits the lock.

cc @andrewhickman

Copy link
Contributor

@mgravell mgravell left a comment

Choose a reason for hiding this comment

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

Logic checks out

@JamesNK JamesNK merged commit 0ab3ada into grpc:master Jul 26, 2023
2 checks passed
@JamesNK JamesNK deleted the jamesnk/retry-cancel-deadlock branch July 26, 2023 06:35
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.

Deadlock when cancelling active call while disposing channel
2 participants