Bug 24663 - HttpWebRequest.Timeout not throwing exception after specified time
Summary: HttpWebRequest.Timeout not throwing exception after specified time
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-11-19 12:23 UTC by Anubhav Ranjan
Modified: 2017-08-08 17:42 UTC (History)
5 users (show)

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

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.

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.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Anubhav Ranjan 2014-11-19 12:23:31 UTC
One of the client is having an issue with HttpWebRequest. They are trying to throw Request Timeout error in case they don't receive the response within 60 seconds. Even though the timeout is set, there are no timeout exception after the specified time.

Code Snippet:

public async Task<bool> ExecuteRequest(string request, IDictionary<string, string> headers, string url, HttpResponseEventHandler handler)

    WebResponse webResponseResult = null;
    ResponseCode status = ResponseCode.NotConnectedToNetwork;
        ServicePointManager.ServerCertificateValidationCallback = delegate
            return true;

        CreateWebRequest(url, headers, null, null, HttpVerbs.Post);
        InsertMessageIntoWebRequest(request, httpRequest);

        Task<WebResponse> asyncResult = httpRequest.GetResponseAsync();
        webResponseResult = await asyncResult;
        status = (ResponseCode)((webResponseResult as HttpWebResponse).StatusCode);
    catch (WebException webException)
    catch (Exception exception)

    return false; 

private HttpWebRequest CreateWebRequest(string url, IDictionary<string, string> headers,
        string userName, string password, string requestMethod = "POST")
    httpRequest = (HttpWebRequest)WebRequest.Create(url);
    httpRequest.Timeout = 60000;

    foreach (var key in headers.Keys)
        httpRequest.Headers.Add(key, headers[key]);

    httpRequest.ContentType = "text/xml; charset=utf-8";
    httpRequest.Accept = "text/xml";
    httpRequest.Method = requestMethod;
    if (userName != null && password != null)
        httpRequest.Credentials = new NetworkCredential(userName, password);
    return httpRequest;
Comment 2 asimk 2014-12-31 05:29:13 UTC
I have checked this issue with the help of sample app attached in comment 1 and not able to reproduce it. I observed that when I click on Button it does not able to find the given url( And after 1 or 2 minute we get the Connection Timeout exception.

Please refer the screencast: 

Please review the screencast and let us know what additional steps we need to
follow to reproduce this issue.

Also, It would be great If you provide log details also. You can find xamarin log details from VS menu HELP -> Zip Xamarin Log and output log details form VIEW -> Output.

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

Xamarin (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 3 Jon Douglas [MSFT] 2017-08-08 17:42:00 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.