Skip to content

Commit 874cb55

Browse files
authored
Fix flakiness when calling GetStatus after error (#1083)
1 parent e36e121 commit 874cb55

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Grpc.Net.Client/Internal/GrpcCall.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
491491
if (status.Value.StatusCode != StatusCode.OK)
492492
{
493493
finished = FinishCall(request, diagnosticSourceEnabled, activity, status.Value);
494-
SetFailedResult(status.Value);
495494
}
496495
else
497496
{
@@ -504,10 +503,15 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
504503
status = new Status(StatusCode.Internal, "Failed to deserialize response message.");
505504

506505
finished = FinishCall(request, diagnosticSourceEnabled, activity, status.Value);
507-
SetFailedResult(status.Value);
508506
}
509507

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

550+
// Set failed result makes the response task thrown an error. Must be called after
551+
// the response is finished. Reasons:
552+
// - Finishing the response sets the status. Required for GetStatus to be successful.
553+
// - We want GetStatus to always work when called after the response task is done.
546554
SetFailedResult(status.Value);
547555
}
548556
else
@@ -558,6 +566,10 @@ private async Task RunCall(HttpRequestMessage request, TimeSpan? timeout)
558566
}
559567
else
560568
{
569+
// Set failed result makes the response task thrown an error. Must be called after
570+
// the response is finished. Reasons:
571+
// - Finishing the response sets the status. Required for GetStatus to be successful.
572+
// - We want GetStatus to always work when called after the response task is done.
561573
SetFailedResult(status.Value);
562574
}
563575
}

0 commit comments

Comments
 (0)