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