Skip to content

Commit

Permalink
[Mono.Android] Increase AndroidClientHandler timeouts (#3328)
Browse files Browse the repository at this point in the history
Context: http://work.devdiv.io/911705
Context: xamarin/xamarin-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.
  • Loading branch information
grendello authored and jonathanpeppers committed Jul 9, 2019
1 parent f951e60 commit 16c4494
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ public bool RequestNeedsAuthorization {
/// cref="t:System.TimeSpan.Zero"/>
/// </para>
/// <para>
/// The default value is <c>100</c> seconds, the same as the documented value of <see
/// cref="t:System.Net.Http.HttpClient.Timeout"/>
/// The default value is <c>24</c> hours, much higher than the documented value of <see
/// cref="t:System.Net.Http.HttpClient.Timeout"/> and the same as the value of iOS-specific
/// NSUrlSessionHandler.
/// </para>
/// </summary>
public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromSeconds (100);
public TimeSpan ReadTimeout { get; set; } = TimeSpan.FromHours (24);

/// <summary>
/// <para>
Expand All @@ -192,7 +193,7 @@ public bool RequestNeedsAuthorization {
/// The default value is <c>120</c> seconds.
/// </para>
/// </summary>
public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromSeconds (120);
public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromHours (24);

protected override void Dispose (bool disposing)
{
Expand Down

0 comments on commit 16c4494

Please sign in to comment.