-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected TaskCanceledException when HttpClient.SendAsync fails possibly due to connection issue #35340
Comments
Tagging subscribers to this area: @dotnet/ncl |
You can get cancel exception on timeout @appel1. It is possible timeout hit when waiting in FillAsyns. You can play with Timeout value on HttpClientHandler as well as do packet capture. |
Seems to me like you would like TaskCanceledException to be reserved for the case when a task is canceled using a CancellationToken. This would be my expectation. |
@wfurt That's very unexpected considering the documentation states that SendAsync throws a HttpRequestException for timeouts. |
I'm wondering @karelz if we could update the docs since we clearly have versions with different behavior. Perhaps simply remove references to timeout. |
@wfurt Yes, it looks like the same as that issue. And depending on where you are in SendAsync you get different inner exceptions or none in the TaskCanceledException. Don't agree that using TaskCanceledException in the case of a timeout is a good idea. Very unintuitive and breaks things like DataFlow that doesn't expect you to misuse TaskCanceledException in this manner. |
give it try with 5.0. It is unlikely 3.x will change at this point. |
Looks like 5.0 still throws a TaskCancelledException for timeouts, but a little nicer since the mandatory try-catch can now inspect the inner exception to find out that it was a timeout. Hopefully this can be highlighted very clearly in the docs since it causes a mess if you are not careful together with DataFlow. runtime/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs Lines 600 to 604 in b4439ca
|
Triage:
|
Created a PR in docs repo dotnet/dotnet-api-docs#4340 |
Documentation PR dotnet/dotnet-api-docs#4340 is merged. |
.NET Core 3.1
Is it intentional that HttpClient.SendAsync throws TaskCanceledException when the connection is aborted? It doesn't work very well together with DataFlow that silently swallows TaskCanceledException.
Is this behavior documented anywhere so we can rely on the fact that a TaskCanceledException with an inner IOException means that we had some kind of connection failure and is not a cancelation at all?
The text was updated successfully, but these errors were encountered: