Open molinch opened 9 years ago
In fact it's even more weird: the standard GetAsync() is also affected
var cancelReadTokenSource = new CancellationTokenSource();
cancelReadTokenSource.CancelAfter(TimeSpan.FromSeconds(15));
var response = await httpClient.GetAsync("http://notexisting.com/notexisting.jpg", cancelReadTokenSource.Token).ConfigureAwait(false);
It won't stop at 15 seconds, instead it will wait 1mn. The worst part is that all other requests are blocked until this one fails...
Are you awaiting the task?
Of course :) I updated the code to reflect that. In fact it's the same code on iOS, there it works perfectly fine. It's really just on Android that it behaves weirdly.
I'm pretty sure it's related to that https://github.com/square/okhttp/issues/1792#issuecomment-131018682 but my knowledge stops here...
Using Mono HttpClient this issue doesn't happen. It errors in time and doesn't cause any other request to be blocked.
Mono implementation outputs this in the console log:
Generating/retrieving image: http://notexisting.com/notexisting.jpg [] _wapi_connect: error looking up socket handle 0x3b
On Android if ModernHttpClient GetAsync method is called with
HttpCompletionOption.ResponseHeadersRead
and a CancelationToken is specified then the token status is never checked while connecting/retrieving headers.Currently if you have a token that cancels after 15 seconds and httpClient cannot connect to the website/get the headers in these 15 seconds, it will continue until it miserably fails.
Example:
Request will not stop after 15 seconds. Instead it takes a while and at some point throws a ConnectException. Please note that even the HttpClient.Timeout is not taken into consideration (on my side it was set to 30s), it just throw at 1 mn.
Stacktrace:
The interesting part is that it will even block other requests until this one fails. Really strange.