Skip to content

Commit 9fa7775

Browse files
grendellojonathanpeppers
authored andcommitted
[Mono.Android] Increase AndroidClientHandler timeouts (#3328)
Context: http://work.devdiv.io/911705 Context: dotnet/macios@30d60bf `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.
1 parent c308421 commit 9fa7775

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ public bool RequestNeedsAuthorization {
172172
/// cref="t:System.TimeSpan.Zero"/>
173173
/// </para>
174174
/// <para>
175-
/// The default value is <c>100</c> seconds, the same as the documented value of <see
176-
/// cref="t:System.Net.Http.HttpClient.Timeout"/>
175+
/// The default value is <c>24</c> hours, much higher than the documented value of <see
176+
/// cref="t:System.Net.Http.HttpClient.Timeout"/> and the same as the value of iOS-specific
177+
/// NSUrlSessionHandler.
177178
/// </para>
178179
/// </summary>
179-
public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromSeconds (100);
180+
public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromHours (24);
180181

181182
/// <summary>
182183
/// <para>
@@ -192,7 +193,7 @@ public bool RequestNeedsAuthorization {
192193
/// The default value is <c>120</c> seconds.
193194
/// </para>
194195
/// </summary>
195-
public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromSeconds (120);
196+
public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromHours (24);
196197

197198
protected override void Dispose (bool disposing)
198199
{

0 commit comments

Comments
 (0)