So there are two timeout properties that can be set on HttpClient: HttpClient.TimeOut and WebRequestHandler.ReadWriteTimeout.
The first one is just a timeout for the whole request/response, so if a download/upload takes longer than that, I am out of luck and get cut off in the middle of transfer, no questions asked. This can obviously be overridden by setting the timeout to Infinite, but I am not certain what consequences does that have.
Now the latter (ReadWriteTimeOut) - at least to my understanding - should be propagated all the way down to NetworkStream, where it affects how long a request/response stream can block (be idle) until timeout.
The HttpClient is using asynchronous versions of the HttpWebRequest methods, but as stated here:
In the case of asynchronous requests, it is the responsibility of the client application to implement its own time-out mechanism.
It is not explained at all which time-out mechanism they have in mind (network stream idle timeout? timeout for the whole HTTP GET? etc...), so that makes me greatly confused.
So my question is, how exactly does HttpClient handle network/protocol timeouts? I want to use HttpClient to upload/download potentially large files, so for that I set the HttpClient.TimeOut to infinite. But I am worried that by doing so, the app is at risk of waiting infinitely for some event that the server/network refuses to complete.
HttpClient
. Before you do that, set theReadWriteTimeout
property ofWebRequestHandler
to whatever you want. This article might help explain some things.