[Mono-dev] WCF Fail with System.Net.Sockets.SocketException: Connection reset by peer

Rob Wilkens robwilkens at gmail.com
Tue Jun 26 13:59:24 UTC 2012


I'm wondering if this is a bug.....  And maybe a report should be
filed....  Sounds like a similar problem i looked at recently, but that
bug was different because the sample code in the bug report also crashed
in windows.

According to: 
http://www.codeproject.com/Articles/8580/How-to-detect-a-connection-loss-in-Net-Sockets


The way to detect a remotely closed connection is to check if
Socket.Receive (which, incidentally, is the topmost thing on the stack
below) returns 0 or fewer bytes -- so you wouldn't expect an exception,
instead you would expect a 0 return for number of bytes read.

This would seem to match:

http://msdn.microsoft.com/en-us/library/w3xtz6a5.aspx

Which says:

" If the remote host shuts down the Socket
<http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx> connection
with the Shutdown
<http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.shutdown.aspx> method,
and all available data has been received, the Receive
<http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receive.aspx> method
will complete immediately and return zero bytes."

And also says that SocketException is only raised under certain
conditions, the only almost valid match is:

"An operating system error occurs while accessing the Socket
<http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx>."

But i don't think connection reset by peer is necessarily an operating
system exception, it's rather a state of connection indicating we're
disconnected, hence we should be returning zero, not raising an exception.

-Rob

On 06/26/2012 08:49 AM, shahbour wrote:
> Hello
>
> I got an WCF service that is running except at some time if the client send
> a request then close his program directly , ending the session the WCF
> console application crashes with below error 
>
>
> [0x7f0b42f55700:] EXCEPTION handling: System.Net.Sockets.SocketException:
> Connection reset by peer
> [0x7f0b42f55700:] EXCEPTION handling: System.IO.IOException: Read failure
> [0x7f0b42f55700:] EXCEPTION handling: System.IO.IOException: Read failure
>
> Unhandled Exception: System.IO.IOException: Read failure --->
> System.Net.Sockets.SocketException: Connection reset by peer
>   at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, Int32 offset,
> Int32 size, SocketFlags flags) [0x000ad] in
> /usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/Socket.cs:1606
>   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32
> offset, Int32 size) [0x00067] in
> /usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:399
>   --- End of inner exception stack trace ---
>   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32
> offset, Int32 size) [0x00078] in
> /usr/local/src/mono-2.11.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:401
>   at System.Net.RequestStream.Read (System.Byte[] buffer, Int32 offset,
> Int32 count) [0x0003c] in
> /usr/local/src/mono-2.11.1/mcs/class/System/System.Net/RequestStream.cs:142
>   at System.IO.StreamReader.ReadBuffer () [0x00012] in
> /usr/local/src/mono-2.11.1/mcs/class/corlib/System.IO/StreamReader.cs:394
>   at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32
> count) [0x00062] in
> /usr/local/src/mono-2.11.1/mcs/class/corlib/System.IO/StreamReader.cs:471
>   at Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) [0x0004f] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1256
>   at Mono.Xml2.XmlTextReader.PeekChar () [0x00047] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1210
>   at Mono.Xml2.XmlTextReader.ReadContent () [0x0003f] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:1310
>   at Mono.Xml2.XmlTextReader.Read () [0x00141] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader.cs:626
>   at System.Xml.XmlTextReader.Read () [0x0006b] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlTextReader2.cs:564
>   at System.Xml.XmlSimpleDictionaryReader.Read () [0x00000] in
> /usr/local/src/mono-2.11.1/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryReader.cs:253
>   at System.Xml.XmlReader.MoveToContent () [0x00050] in
> /usr/local/src/mono-2.11.1/mcs/class/System.XML/System.Xml/XmlReader.cs:574
>   at System.ServiceModel.Channels.XmlReaderMessage.ReadEnvelopeStart ()
> [0x00000] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:146
>   at System.ServiceModel.Channels.XmlReaderMessage..ctor
> (System.ServiceModel.Channels.MessageVersion version,
> System.Xml.XmlDictionaryReader reader, Int32 maxSizeOfHeaders) [0x00026] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:70
>   at System.ServiceModel.Channels.Message.CreateMessage
> (System.Xml.XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders,
> System.ServiceModel.Channels.MessageVersion version) [0x00022] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:427
>   at System.ServiceModel.Channels.TextMessageEncoder.ReadMessage
> (System.IO.Stream stream, Int32 maxSizeOfHeaders, System.String contentType)
> [0x00011] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TextMessageEncoder.cs:87
>   at System.ServiceModel.Channels.Http.HttpReplyChannel.CreatePostMessage
> (System.ServiceModel.Channels.Http.HttpContextInfo ctxi) [0x00081] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs:229
>   at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest
> (TimeSpan timeout, System.ServiceModel.Channels.RequestContext& context)
> [0x000aa] in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs:172
>   at
> System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__10
> (TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x0002f]
> in
> /usr/local/src/mono-2.11.1/mcs/class/System.ServiceModel/System.ServiceModel.Channels/ReplyChannelBase.cs:126
>
> I couldn't figure out how to check the connection status before trying to
> ReadMessage or CreatePostMessage functions.
>
> Any Help ??
>
>
> --
> View this message in context: http://mono.1490590.n4.nabble.com/WCF-Fail-with-System-Net-Sockets-SocketException-Connection-reset-by-peer-tp4650173.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120626/cb3d15c1/attachment-0001.html>


More information about the Mono-devel-list mailing list