Bug 24704 - System.Net.Http.HttpClient PostAsync ignores timeout if webproxy isn't accessible
Summary: System.Net.Http.HttpClient PostAsync ignores timeout if webproxy isn't access...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-11-20 13:25 UTC by leankitryan
Modified: 2015-02-20 16:42 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description leankitryan 2014-11-20 13:25:13 UTC
A continuation of the issue described here:
https://bugzilla.xamarin.com/show_bug.cgi?id=13200

The timeout is being ignored when connecting to an HTTPS url via a proxy that cannot be reached. 

Sample Code:

			var handler = new HttpClientHandler
			{
				Proxy = new WebProxy("192.168.10.25:8888/"), // proxy that doesn't exist
				UseProxy = true,
				AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
			};

			var httpClient = new System.Net.Http.HttpClient(handler)
			{
				BaseAddress = new Uri("https://google.com"),
				Timeout = TimeSpan.FromSeconds(20)
			};

			Console.WriteLine("Timeout is set to: " + httpClient.Timeout);
			Console.WriteLine("Start: " + DateTime.Now);

			var start = DateTime.Now;

			try
			{
				var restRequest = new HttpRequestMessage
				{
					Method = HttpMethod.Post,
					RequestUri = new Uri("foo", UriKind.Relative),
					Content = new StringContent("", null, "application/json")
				};
						
				await httpClient.PostAsync(restRequest.RequestUri, restRequest.Content);
			}
			catch (Exception e)
			{
				Console.WriteLine("Error: " + e.Message);
			}

			Console.WriteLine("Finished: " + DateTime.Now);
			Console.WriteLine("Duration: " + (DateTime.Now - start).TotalSeconds);
		}

Output on iOS

2014-11-20 11:03:28.573 HttpTimeoutiOS[9315:70b] Timeout is set to: 00:00:20
2014-11-20 11:03:28.582 HttpTimeoutiOS[9315:70b] Start: 11/20/2014 11:03:28 AM
Thread started: <Thread Pool> #5
Thread started: <Thread Pool> #6
Thread started: <Thread Pool> #7
2014-11-20 11:04:43.849 HttpTimeoutiOS[9315:70b] Error: Error: ConnectFailure (Connection timed out)
2014-11-20 11:04:43.850 HttpTimeoutiOS[9315:70b] Finished: 11/20/2014 11:04:43 AM
2014-11-20 11:04:43.852 HttpTimeoutiOS[9315:70b] Duration: 75.267784

Output on Android

Timeout is set to: 00:00:20
Start: 11/20/2014 11:08:33 AM
Error: Error: ConnectFailure (Connection timed out)
Finished: 11/20/2014 11:09:36 AM
Duration: 63.293487

Xamarin Studio 5.5.3 (build 6)

Xamarin.Android
Version: 4.18.1 (Business Edition)
Comment 1 Marek Safar 2014-11-21 07:01:06 UTC
Fixed in mono master
Comment 2 Jonathan Moosekian 2015-02-20 16:42:22 UTC
The timeout is now respected, however, if the timeout is exceeded, instead of throwing a WebException, it throws a TaskCancellationException which is not in line with expected behavior of the HttpClient.

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.


Create a new report for Bug 24704 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: