In .net 5, When timeout happens, HttpClient throws TaskCaneledException. But the innerException is IOException instead of TimeoutException #49116
-
Based on .net 5 document, when timeout happens, HttpClient should throw TaskCanceledException. And the InnerException should be a TimeoutException. But I'm receiving IOException as the InnerException instead. Any reason why this can happen? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Can you give us a full stack trace and the message of the exceptions? An IOException indicates the Stream or Socket threw an exception. It may not have been timeout related. |
Beta Was this translation helpful? Give feedback.
-
OK, got the issue figured out. So this is a .net 5 restriction. The conversion to TimeoutException is at HttpClient level: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs#L586-L591 |
Beta Was this translation helpful? Give feedback.
OK, got the issue figured out. So this is a .net 5 restriction. The conversion to TimeoutException is at HttpClient level: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs#L586-L591
So capturing this inside a delegating handler can't detect the TimeoutException.