Skip to content

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
@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