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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/Retry/HedgingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ private async Task HedgingDelayAsync(TimeSpan hedgingDelay)

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

lock (Lock)
{
base.Dispose(disposing);

CleanUpUnsynchronized();
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/Grpc.Net.Client/Internal/Retry/RetryCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,23 @@ private static bool IsSuccessfulStreamingCall(Status responseStatus, GrpcCall<TR

protected override void OnCommitCall(IGrpcCall<TRequest, TResponse> call)
{
Debug.Assert(Monitor.IsEntered(Lock));

_activeCall = null;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

// Don't dispose the active call inside the retry lock.
// Canceling the call could cause callbacks to run on other threads that want to aquire this lock, causing an app deadlock.
GrpcCall<TRequest, TResponse>? activeCall = null;
lock (Lock)
{
base.Dispose(disposing);

_activeCall?.Dispose();
activeCall = _activeCall;
}
activeCall?.Dispose();
}

protected override void StartCore(Action<GrpcCall<TRequest, TResponse>> startCallFunc)
Expand Down
Loading