Bug 25402 - Connection Reset by Peer Exception
Summary: Connection Reset by Peer Exception
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 8.6.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-15 14:00 UTC by John Miller [MSFT]
Modified: 2016-07-31 16:40 UTC (History)
9 users (show)

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


Attachments

Description John Miller [MSFT] 2014-12-15 14:00:29 UTC
**Overview:**

   The attached private sample project gets an exception occasionally when downloading data using WebRequest.

**Steps to Reproduce:**

   See private info in comment below. 

**Actual Results:**

   An exception is thrown in Socket_2_1.cs public int EndSend (IAsyncResult result)
   "Connection Reset by Peer"

>System.Net.Sockets.Socket.EndSend (result={System.Net.Sockets.Socket.SocketAsyncResult}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1852
>System.Net.Sockets.NetworkStream.EndWrite (ar={System.Net.Sockets.Socket.SocketAsyncResult}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net.Sockets/NetworkStream.cs:340
>Mono.Security.Protocol.Tls.RecordProtocol.EndSendRecord (asyncResult={System.Net.Sockets.Socket.SocketAsyncResult}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:850
>Mono.Security.Protocol.Tls.RecordProtocol.SendRecord (contentType=Mono.Security.Protocol.Tls.ContentType.Alert, recordData={byte[2]}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:858
>Mono.Security.Protocol.Tls.RecordProtocol.SendAlert (alert={Mono.Security.Protocol.Tls.Alert}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:703
>Mono.Security.Protocol.Tls.RecordProtocol.SendAlert (description=Mono.Security.Protocol.Tls.AlertDescription.CloseNotify) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:674
>Mono.Security.Protocol.Tls.SslStreamBase.Dispose (disposing=true) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:1190
>Mono.Security.Protocol.Tls.SslClientStream.Dispose (disposing=true) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs:247
>System.IO.Stream.Close () in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.IO/Stream.cs:113
>Mono.Security.Protocol.Tls.SslStreamBase.Close () in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:918
>System.Net.WebConnection.Close (sendNext=false) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net/WebConnection.cs:1184
>System.Net.WebConnectionGroup.TryRecycle (maxIdleTime={00:01:40}, idleSince={1/1/0001 12:00:00 AM}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net/WebConnectionGroup.cs:219
>System.Net.ServicePoint.CheckAvailableForRecycling (outIdleSince={1/1/0001 12:00:00 AM}) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net/ServicePoint.cs:305
>System.Net.ServicePoint.IdleTimerCallback (obj=(null)) in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Net/ServicePoint.cs:338
>System.Threading.Timer.Scheduler.TimerCB (o={System.Threading.Timer}) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Timer.cs:317

**Expected Results:**

   No Exception.

**Build Date & Platform:**

   === Xamarin Studio ===

Version 5.7 (build 646)
Installation UUID: e01c3049-a2d2-4e0a-aad8-afe6fb627c4d
Runtime:
	Mono 3.12.0 ((detached/dc0ce1d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000066

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.0.22 (Business Edition)
Hash: 142934d
Branch: 
Build date: 2014-12-09 10:40:45-0500

=== Build Information ===

Release ID: 507000646
Git revision: 4574f534cc8c822ac1a4b2f31450250afb6511d3
Build date: 2014-12-09 16:28:52-05
Xamarin addins: c3c87b666323c163f0ad02618d1753533cf0a4f9

=== Operating System ===

Mac OS X 10.10.0

**Additional Information:**

   The project provided by the customer will reproduce this error, but it did take a few attempts. Eventually the stack trace from the crash will be related to Protobuf.net not being able to deserialize the response, however I think the underlying issue is someone in the network stack. 
   I have gotten a few stack traces trying to track this down, please see the attached Trace.txt for them. 
   The protobuf exception is "Sub-message not read correctly", but I am not sure that is actually related to the problem. I think this exception in Protobuf would be expected considering the webclient response threw an exception.
Comment 3 Miguel de Icaza [MSFT] 2014-12-19 14:14:49 UTC
The stack trace is not very useful, because it is normal for that to throw in that location (and it is being caught in that place WebConnection.cs:1184).   So what you are seeing is just the normal behavior.

What we need is the actual description of the problem when the application is executed, ignoring the changes that the debugging execution environment does (in this case, setting those flags for catching all exceptions).
Comment 4 John Miller [MSFT] 2014-12-19 18:05:18 UTC
@Miguel,

Sorry it was unclear. Here is what the customer is reporting

"Random requests are coming back with a 'Connection Reset by Peer' exception that is timing after a lengthy wait. (around 60 seconds)."

Its unclear why these exceptions happen and why the webrequest timeout. I was able to reproduce this per my private comments above.
Comment 9 Miguel de Icaza [MSFT] 2015-01-16 12:54:16 UTC
Hello John,

We do not have any updates.   Did you get a simpler test case created?

One idea that I had was that the user could replace the raw use of HttpWebRequest, with HttpClient, and use the CFNetwork transport.

If they are not tied to HttpWebRequest, this has many advantages, for example, it automatically turns on the radio on phones.
Comment 10 John Miller [MSFT] 2015-01-19 13:55:01 UTC
Thanks Miguel,

No simpler test case is available. The project provided does reproduce this issue.
Comment 11 Dennis Welu 2015-02-06 12:20:37 UTC
Fwiw, I've been trying to run down this same exception that happens "randomly" based on outward appearances. And I see it on both iOS and Android. The short stack I have from Xam Insights shows it on the receiving/reading end:

  at System.Net.Sockets.Socket.EndReceive (IAsyncResult result) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0
Comment 12 Laura Zarioiu 2015-04-01 05:08:13 UTC
I am already using HttpClient and I do receive this error. It's random and appears only in the iOS application, not in the Windows app. Din changing HttpWebRequest to HttpClient work for anyone ?
Comment 13 fred 2015-05-04 16:31:09 UTC
i am also getting this exception. i am using HttpClient

Note You need to log in before you can comment on or make changes to this bug.