Bug 2031 - HTTPS (SSL) - EndWrite failure
Summary: HTTPS (SSL) - EndWrite failure
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 2.0
Hardware: PC Windows
: Highest normal
Target Milestone: 4.8 (async)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-15 01:01 UTC by Stuart Lodge
Modified: 2013-06-28 14:08 UTC (History)
6 users (show)

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


Attachments
Project / binary (441.56 KB, application/zip)
2012-05-07 14:16 UTC, Chris Schamper
Details


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:
Status:
RESOLVED NORESPONSE

Description Stuart Lodge 2011-11-15 01:01:50 UTC
I can't get any HTTPs code to work at present.

According to Help|About I'm running MonoDevelop.MonoDroid - 2.6.0.0 - with a download from MonoDroid a couple of days ago - "Mono for Android: 1.2.24817.105690530 (Evaluation)"

The full report is here: http://stackoverflow.com/questions/8124854/i-cant-download-from-https-on-monodroid-am-i-missing-something-obvious

The failing code is:

        var wc = new WebClient ();
        var test1 = wc.DownloadString("http://www.google.com");
        var test2 = wc.DownloadString("https://www.google.com");

- test1 succeeds, test2 exceptions with:

{System.Net.WebException: Error getting response stream (Write: EndWrite failure): SendFailure ---> System.IO.IOException: EndWrite failure ---> System.Net.Sockets.SocketException: The socket has been shut down at System.Net.Sockets.Socket.EndSend (IAsyncResult result) [0x0002d] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1989 at System.Net.Sockets.NetworkStream.EndWrite (IAsyncResult ar) [0x0002f] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net.Sockets/NetworkStream.cs:358 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.EndWrite (IAsyncResult ar) [0x0003d] in /home/jon/Development/xamarin/mono/mcs/class/System/System.Net.Sockets/NetworkStream.cs:360 at Mono.Security.Protocol.Tls.RecordProtocol.EndSendRecord (IAsyncResult asyncResult) [0x00040] in /home/jon/Development/xamarin/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:721 at Mono.Security.Protocol.Tls.RecordProtocol.SendRecord (ContentType contentType, System.Byte[] recordData) [0x0000b] in /home/jon/Development/xamarin/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:729

I see this in every HTTPs call that I try to make - HTTPWebRequest as well as WebClient.
Comment 1 Stuart Lodge 2011-11-17 16:40:04 UTC
Thanks for escalating this.

If it helps, I've had some feedback that this is only in the evaluation version at present - it's not in the beta/rc for 2.0

Hopefully accounts will raise the PO for MonoDroid soon - then I'll find out for myself!

Stuart
Comment 2 Craig 2012-02-15 10:46:56 UTC
Just to note, I am currently using the latest stable FULL version and this bug still exists (version 4.0.3 according to Visual Studio -> Help -> About)

The same code executes fine in a standard visual studio project but throws EndWrite error in Mono for Android.

It's a pretty significant bug, will this be fixed soon?  Or are there any workarounds?  I am targeting Android platform 2.1, not sure if that matters or not.
Comment 3 Eric Beisecker 2012-02-28 12:47:35 UTC
Is this still happening in 4.0.4? 

I've run the code sample given in the Bug Description in Visual Studio 2010 with MfA 4.0.4 and on Mac with MonoDevelop and haven't seen this issue.
Comment 4 Chris Schamper 2012-05-07 14:15:39 UTC
Greetings,

This, or a related bug, seems to be present in the current alpha. Both test1 and test2 fail. Attaching project with build binary.


------------------

System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/monodroid-mac-master/bc064d64/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:828

  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in /Users/builder/data/lanes/monodroid-mac-master/bc064d64/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:836

  at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in /Users/builder/data/lanes/monodroid-mac-master/bc064d64/source/mono/mcs/class/System/System.Net/WebClient.cs:1464

  at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in /Users/builder/data/lanes/monodroid-mac-master/bc064d64/source/mono/mcs/class/System/System.Net/WebClient.cs:896

  at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x0000a] in /Users/builder/data/lanes/monodroid-mac-master/bc064d64/source/mono/mcs/class/System/System.Net/WebClient.cs:256
Comment 5 Chris Schamper 2012-05-07 14:16:26 UTC
Created attachment 1823 [details]
Project / binary
Comment 6 Chris Schamper 2012-05-07 14:20:36 UTC
Running Mono for Android: 4.1.1.197158102
Comment 7 Jonathan Pryor 2012-05-07 16:33:55 UTC
@Chris: I'm unable to reproduce. There are a number of factors:

1. Your test code is buggy: "Success!" will never be shown, as the Toast is never shown. You need to call Show() on the value returned from Toast.MakeText():

    Toast.MakeText(this, "Success!", ToastLength.Long).Show();

2. In a Release build, this will fail because the INTERNET permission isn't present within AndroidManifest.xml (because there is no AndroidManifest.xml). You can add this permission in Project Properties/Options.

3. In a Debug build, it works for me on a N1.

3(a): To help verify this, I changed the button.Click event handler to do:

    button.Text += " Downloaded " + test1.Length + " chars!";

(This is how I found out that the Toast wasn't doing anything: my button was updated but I wasn't seeing the Toast. I figured I just wasn't looking hard enough 'til I saw the missing .Show()...)

4. The device must have network connectivity. It's easy to enable or disable networking within the emulator by using F8.

A quick way to test for this is to launch the Browser app and see if it will load the site w/o prompting. (If it shows a prompt regarding SSL certificates, this will _normally_ cause WebClient to fail unless you set the ServicePointManager.ServerCertificateValidationCallback property.

    http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx

What device/hardware are you running on, and is this a Debug or Release build?

Thanks,
 - Jon
Comment 9 PJ 2013-06-28 14:08:04 UTC
No response on this NEEDINFO bug for over a year. RESOLVING as NORESPONSE.

Chris, please feel free to REOPEN or re-file with the requested details in Comment 7.