Bug 20833 - HttpWebRequest timed out or takes too long time from separate thread on xamarin v3.0.56
Summary: HttpWebRequest timed out or takes too long time from separate thread on xamar...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.1.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
URL: HttpWebRequest_timed_out_or_takes_too...
Depends on:
Reported: 2014-06-24 02:54 UTC by Alex
Modified: 2016-08-30 21:11 UTC (History)
4 users (show)

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

app to reproduce in the attachment. (27.19 KB, application/octet-stream)
2014-06-25 02:46 UTC, Alex
logcat with issue (346.61 KB, text/plain)
2014-06-25 08:45 UTC, Alex
logcat without issue (403.70 KB, text/plain)
2014-06-25 08:46 UTC, Alex

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 Alex 2014-06-24 02:54:27 UTC
HttpWebRequest timed out or takes too long time from separate thread on xamarin v3.0.56 

Hi all, i started to observe this issue  just with current version xamarin(v3.0.56) and one version before.

my code:
            HttpWebRequest webRequest = null;
            webRequest = (HttpWebRequest)WebRequest.Create(_apiUrl);
            webRequest.ContentType = "application/json; charset=utf-8";
            // webRequest.acce = "gzip, deflate";
            webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy();
            webRequest.Method = "POST";
            webRequest.Timeout = 20000;
            webRequest.AllowWriteStreamBuffering = false;
            webRequest.Accept = "*/*";
            webRequest.KeepAlive = true;
            webRequest.ServicePoint.ConnectionLimit = 10;
            if (requestHeader != null)

            callBinary = Encoding.UTF8.GetBytes(requestBody);
            webRequest.ContentLength = callBinary.Length;

           	using (Stream dataStream = webRequest.GetRequestStream())
                dataStream.Write(callBinary, 0, callBinary.Length);

            System.Diagnostics.Debug.WriteLine("Obtained webresponse");
            var response = ReadResponse(webRequest);

and all request are timed out or take too long time(response size is less 1 kb). I can reproduce this on the device:
device: galaxy tab 3(SM-T210)
Kernel version: 3.4.5-1256430-user(T210XXANC2)
proc details: arm cortex - a9 2 cores, revision r3po
android version: 4.1.2

Xamarin details:
version: 3.0.56,
api: api 14, api 15

this issue i have when i make request on the separate thread(using TaskFactory). On the ui thread  request are pretty fast!!!
NOTE: i'm using armeabi-v7a, armeabi 

i tried already:
-increase System.Net.ServicePointManager.DefaultConnectionLimit
- change csproj from "<AndroidSupportedAbis>armeabi,armeabi-v7a</AndroidSupportedAbis>" to "<AndroidSupportedAbis>armeabi-v7a,armeabi</AndroidSupportedAbis>"
- tried to use just "armeabi-v7a".
- tried to use  api 14, api 15
- tried to reinstall xamarin android.
- use an other ways to create thread(currently use TaskFactory).

NOTE: i do not observe this bug for example on the galaxy s3 i9300 with the same proc family.

Please advice!
Comment 1 Udham Singh 2014-06-24 04:43:21 UTC
We have tried to reproduce this issue with code provided in bug description but not able to reproduce this.

Could you please provide a sample application in which you are getting this issue, so that we can reproduce this issue at our end?

Environment Info :

Windows 8.1
Xamarin Studio: 5.0.1 (build 3)
Xamarin :
Xamarin.Android :
Comment 2 Alex 2014-06-25 02:46:19 UTC
Created attachment 7174 [details]
app to reproduce in the attachment.
Comment 3 Alex 2014-06-25 02:49:33 UTC
app is in the attachment.  App makes one request to the server and it takes for me up to 5 sec.

Comment 4 Udham Singh 2014-06-25 05:55:45 UTC
Thanks Alex

I have checked this issue with the app attached in comment 2 and observed that app makes one request to the server and for me it takes 2-3 sec to return result from the server. I have checked this issue in both XS and VS, and observed the same behavior.

Note : I have checked this issue on devices Samsung galaxy tab 3(SM-T311) and galaxy s3, and observed the same behavior with both devices.

Screencast : http://www.screencast.com/t/HqAUWATu

Environment Info :

Windows 8.1
VS 2013
Xamarin Studio: 5.0.1 (build 3)
Xamarin :
Xamarin.Android :
Comment 5 Alex 2014-06-25 06:18:25 UTC
Can see different android version and phone model between your and mine... Possible i can send to you logcat logs from my app and that may be helpful? 

Comment 6 Udham Singh 2014-06-25 06:42:55 UTC
Thanks Alex
Please attach your application logs.
Comment 7 Alex 2014-06-25 08:45:47 UTC
Created attachment 7176 [details]
logcat with issue
Comment 8 Alex 2014-06-25 08:46:20 UTC
Created attachment 7177 [details]
logcat without issue
Comment 9 Alex 2014-06-25 09:08:36 UTC
please find two logcat files in the attachments.
first one - on the phone without time issue and second one contains logs for my galaxy tab 3(SM-T210) with webrequest time issue.
I used exactly the same workflow on the both devices so logs contain the same requests. I'm using the same wifi without limitations.

1-Please find for example following lines(response starting/obtained) for "datasource.getOne" api request in the logcatwithissue.txt:

06-25 17:24:36.585 I/InformedLog(15900): Type: All;  starting webrequest; request body :{"jsonrpc":"2.0", "method": "datasource.getOne", "params": {"datasource_id":3},"id": "2f20bfbaa85e4e439d629ac57d114f81", "debug":1}; Time: 25.06.2014 15:24:36

and response obtained:

06-25 17:24:45.515 I/InformedLog(15900): Type: All;  Response obtained : {"jsonrpc":"2.0","id":"2f20bfbaa85e4e439d629ac57d114f81","result":{"total":367,...

as you can see time between reques starting/obtained  ~ 9 sec.

the same request in the "logcat without issue.txt" takes less 1sec. server time processing for both requests ~0.2 secs.
this is related almost for all web requests in the log.

2- Also i found the set of the exceptions in the " logcat with issue " with message like like :
06-25 17:24:45.585 E/TerminalConnectIntentService( 9522): com.adyen.library.exceptions.NotYetRegisteredException: Not yet registered...

May this exception cause the problem?

3- possible you will find something new in the logs.

Comment 10 Alex 2014-07-01 01:45:44 UTC
Hi Udham Singh, 
do you have any updates about this issues? this issue is really important for us... 

Comment 11 Udham Singh 2014-07-01 04:21:10 UTC
Hi Alex,

I am still not able to reproduce this issue, we may have to see if a developer can figure out what's going on from the logs attached.

Comment 12 Alex 2014-07-01 04:26:43 UTC
Yes , please ask your developer to review the logs. i believe that contains helpful info to figure out the issue.

Comment 13 glucose1e 2015-05-13 00:59:46 UTC
Same problem happened to me.
When I create just one task of HttpWebRequest, everything is fine and the response is quick.
But if I create 20 tasks of HttpWebRequest to different hosts, after that, when I create the 21st task, the last one is extremely slow. 
The HttpWebRequest seems have problem in multi-thread and fast frequency situation.
Comment 14 Marek Habersack 2016-08-30 21:11:10 UTC
This issue no longer exists with the current Xamarin.Android versions:

 - master
 - cycle8
 - alpha

Testing shows that the response is well below 1s, please reopen