From 16c4494d5e234d5b5b7aed8cf759f8e68b836b31 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 5 Jul 2019 19:23:23 +0200 Subject: [PATCH] [Mono.Android] Increase AndroidClientHandler timeouts (#3328) Context: http://work.devdiv.io/911705 Context: https://github.com/xamarin/xamarin-macios/commit/30d60bffe92f84bba73bbc21a262fbd3fed86c8f `AndroidClientHandler` has no way of accessing the `HttpClient.Timeout` property in order to set the timeout value of *two* native http client properties (connect and read timeouts), so it uses two custom properties to provide these values. So far, the values were set to 100 seconds for the read timeout and 120 seconds for the connect timeout, which seemed to be a reasonable value for their purposes. However, if a developer sets `HttpClient.Timeout` to a value *larger* than our defaults, `AndroidClientHandler` values "win" and the connection/read times out earlier. The workaround is to set "our" timeouts along with the `HttpClient` one, but if the developer cannot do it, for any kind of reasons (i.e. to avoid platform-specific code), then they are faced with an annoying situation. The real fix would be to improve `HttpClient` API so that its associated client handler can access `HttpClient` properties, but as that's not a quick fix we can implement now, we instead bump the default timeout values to the (unreasonable) value of 24 hours to make sure we use values higher than the most likely figures assigned to `HttpClient.Timeout`, and to match the Xamarin.iOS `NSUrlSessionHandler` defaults. --- .../Xamarin.Android.Net/AndroidClientHandler.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs b/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs index e6b871cd774..53afea03358 100644 --- a/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs +++ b/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs @@ -172,11 +172,12 @@ public bool RequestNeedsAuthorization { /// cref="t:System.TimeSpan.Zero"/> /// /// - /// The default value is 100 seconds, the same as the documented value of + /// The default value is 24 hours, much higher than the documented value of and the same as the value of iOS-specific + /// NSUrlSessionHandler. /// /// - public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromSeconds (100); + public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromHours (24); /// /// @@ -192,7 +193,7 @@ public bool RequestNeedsAuthorization { /// The default value is 120 seconds. /// /// - public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromSeconds (120); + public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromHours (24); protected override void Dispose (bool disposing) {