Skip to content

Commit

Permalink
Fix flakiness when calling GetStatus after error (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Oct 22, 2020
1 parent e36e121 commit 874cb55
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Grpc.Net.Client/Internal/GrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
if (status.Value.StatusCode != StatusCode.OK)
{
finished = FinishCall(request, diagnosticSourceEnabled, activity, status.Value);
SetFailedResult(status.Value);
}
else
{
Expand All @@ -504,10 +503,15 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
status = new Status(StatusCode.Internal, "Failed to deserialize response message.");

finished = FinishCall(request, diagnosticSourceEnabled, activity, status.Value);
SetFailedResult(status.Value);
}

FinishResponseAndCleanUp(status.Value);

// Set failed result makes the response task thrown an error. Must be called after
// the response is finished. Reasons:
// - Finishing the response sets the status. Required for GetStatus to be successful.
// - We want GetStatus to always work when called after the response task is done.
SetFailedResult(status.Value);
}
else
{
Expand Down Expand Up @@ -543,6 +547,10 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
FinishResponseAndCleanUp(status.Value);
finished = FinishCall(request, diagnosticSourceEnabled, activity, status.Value);

// Set failed result makes the response task thrown an error. Must be called after
// the response is finished. Reasons:
// - Finishing the response sets the status. Required for GetStatus to be successful.
// - We want GetStatus to always work when called after the response task is done.
SetFailedResult(status.Value);
}
else
Expand All @@ -558,6 +566,10 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
}
else
{
// Set failed result makes the response task thrown an error. Must be called after
// the response is finished. Reasons:
// - Finishing the response sets the status. Required for GetStatus to be successful.
// - We want GetStatus to always work when called after the response task is done.
SetFailedResult(status.Value);
}
}
Expand Down

0 comments on commit 874cb55

Please sign in to comment.