Bug 7002 - Concurrent HttpWebRequest timing out in Mono for Android 4.2.5
Summary: Concurrent HttpWebRequest timing out in Mono for Android 4.2.5
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Martin Baulig
Depends on:
Reported: 2012-09-07 18:48 UTC by Maximo Martinez
Modified: 2012-10-29 11:22 UTC (History)
9 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 Maximo Martinez 2012-09-07 18:48:53 UTC
Since installing Mono for Android 4.2.5 today doing concurrent HttpWebRequest often results in timeouts. Here is a summary of how I'm creating the requests:

Task.Factory.StartNew(() =>
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(BaseUrl + endpoint));
    try {
        var userPass = Convert.ToBase64String(Encoding.UTF8.GetBytes(Username + ":" + Password));
        request.Headers[HttpRequestHeader.Authorization] = "Basic " + userPass;
        request.Accept = MEDIA_TYPE;
        request.CookieContainer = new CookieContainer();
        request.PreAuthenticate = true;
        request.Method = method;
        request.UserAgent = string.Format("{0}/{1}", ProductName, ProductVersion);
    } catch(Exception e) {
        return null;
    HttpWebResponse response = null;
        response = request.GetResponse() as HttpWebResponse;
    catch (WebException e) {
        response = e.Response as HttpWebResponse;
    catch (Exception e)
        return null;
    return response;

Adding a lock inside the task method so that only one request is done at a time works around the problem.
Comment 1 Matthijs Koopman 2012-09-18 05:37:18 UTC
I can confirm this issue, we are facing the same issue and it goes way beyond what you described.

It appears that the streams are being passed along other requests, resulting in an other request ending up with the output of the first request.

So e.g.

Request one: http://www.somedomain.com/someimage.png
Request two: http://www.somedomain.com/someotherimage.png

In some cases the completed handler for request two will en up with the content / bytes of request one. 
Ending up with corrupted files...

This is also being described in this bug report but it's for monotouch: https://bugzilla.xamarin.com/show_bug.cgi?id=7200
Comment 2 Jared Reed 2012-09-19 15:27:27 UTC
I'm seeing the timeout issue and the jumbled responses for requests.
I logged Bug 7308 for what I was seeing.
Comment 4 Miguel de Icaza [MSFT] 2012-09-26 16:06:50 UTC

Could we get a self-contained test case?

The description is not complete enough, because timeouts are possible if you overflow the size of the system threadpool (which is what the Task.Default uses)
Comment 5 Martin Baulig 2012-09-26 20:54:28 UTC
A test case should not be required here, this looks pretty much like the issue in bug #7200.

This is a regression in Mono's class libraries which broke concurrent web requests.
Comment 6 Martin Baulig 2012-10-29 11:22:20 UTC
Bug #7200 should have fixed this issue, please reopen the bug if you're still having problems.