MetalPuppyTheThird
MetalPuppyTheThird
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
The client requests to give a car in the response. There are 3 services, one to create the engine, one to create the body, and one to do the electricals. Client gives a 20s timeout to the app. The services, by historical data and agreement, are decided that they will complete their task in 5s each. Now, one of the service, a shitty service - electricals in this instance, takes 8s or 10s to do it's thing. Don't care why, but it takes that much time. Now I've passed a 5s timeout to that service -- which is not being respected. I create that 5s timeout by using linkedTokenSource. What is happening currently is, the runtime( whole app ) is >20s since that shitty service is not respecting the token. When it takes > cancellationToken, eventually it fails with a TaskCancelledException, post that, the application observes the original token is also marked cancelled so it too times out.
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
vice versa is true though
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
no
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
apologies, let me elaborate in a simple way. My use case is : call n services in X time. X is the original cancellationToken. One of these n services is the one that I have described above. This service has to have it's own cancellationToken which must be < original cancellationToken so as to give other services their own time to run. The tokens that is passed to these services are created by doing a createLinkedTokenSource(originalToken) and cancelAfter(time_for_this_particular_service)
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
I don't know if cts is the same as cancellationToken in the SendAsync method or PostAsync
It is the same
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
the whole end to end process has allowed runtime of X timespan. This HttpClient call that I describe has allowed runtime of Y timespan. X > Y always
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
yeah but I think that would not solve my problem. The token passed to the HttpClient is X. X must cancel after Y timespan. but it is not. Would like to point that the linkedTokenSource is needed because this call has to be capped to a certain value. My use case is the original token cannot be passed to this HttpClient call as the call has a different "max run time" setup in the config.
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
hrm, but the linkedsource cancellationRequested is tied to the one passed to it
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
thanks for the tip! from the SO, IMO this looks like a fairly common problem and yet there's no recommended solutions for this
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
More details on what is desired state - Ideally : If app X can tell Y to stop processing because X does not care anymore Not Ideal but can work : X can chop off the call to Y and Y can keep processing the request
28 replies
CC#
Created by MetalPuppyTheThird on 5/6/2023 in #help
❔ HttpClient does not respect CancellationToken
Additional Details 1. HttpClient is initialised as a singleton 2. HttpClient.Timeout is set to 10mins 3. The Polly.Timeout() solution was implemented using the Optimistic Strategy as recommended in the readme
28 replies