1

I have service A which calls service B using a client to the service which also has a default timeout of 5 seconds.

The code in service A looks like this:

var response = _serviceBClient.DoStuff(requestParams, cancellationToken).ContinueWith(task =>
{
...
}
, cancellationToken)

The client then makes a rest call to Service B controller using PostAsync and passes the CT it got.

I want to be able to recognize the 2 cases inside service B: when the CT from service A is canceled vs the HttpClient received a timeout. Is there a way to do it?

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Balon
  • 19
  • 2
  • See also https://github.com/dotnet/runtime/issues/21965 for the arguments behind how to differentiate them. It became a three level `InnerException` because of backwards compatibility – Charlieface Jul 05 '23 at 01:13
  • If would you decorate your `HttpClient` with [Polly's timeout](https://github.com/App-vNext/Polly/wiki/Timeout) then the timeout would be manifested as `TimeoutRejectedException` which would ease the detection. – Peter Csala Jul 05 '23 at 12:32

0 Answers0