[Mono-bugs] [Bug 53168][Blo] New - Operation on non-blocking socket would block

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 21 Jan 2004 09:10:19 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mikeg_us@hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=53168

--- shadow/53168	2004-01-21 09:10:19.000000000 -0500
+++ shadow/53168.tmp.2667	2004-01-21 09:10:19.000000000 -0500
@@ -0,0 +1,103 @@
+Bug#: 53168
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 8.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Blocker
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mikeg_us@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Operation on non-blocking socket would block
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+Using non-blocking sockets, sending and receiving megabytes of data, I 
+sometimes receive this exception:
+
+Unhandled Exception: System.Net.Sockets.SocketException: Operation on non-
+blocking socket would block
+in (unmanaged) /usr/lib/libmono.so.0(mono_raise_exception+0x20) 
+[0x400aea94]
+in (unmanaged) /usr/lib/libmono.so.0 [0x400cc16d]
+in <0x000e8> System.Net.Sockets.Socket:Send (byte
+[],int,int,System.Net.Sockets.SocketFlags)
+in <0x00102> System.Net.Sockets.Socket:Send (byte
+[],int,int,System.Net.Sockets.SocketFlags)
+in <0x00056> .Worker:Send ()
+in <0x00044> (wrapper delegate-invoke) 
+System.MulticastDelegate:invoke_void ()
+
+
+The socket remains open, but is one directional.  I can only receive on 
+it, not send.  I would like to be able to catch the exception, 
+Thread.Sleep for a small amount of time and then try the BeginSend 
+again.  Since the exception occurs on the Worker thread, my code is never 
+notified that the problem even happened.
+
+
+Steps to reproduce the problem:
+This is not complete code, but it should get you started...
+Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, 
+ProtocolType.Tcp);
+socket.Blocking = false;
+socket.SetSocketOption(SocketOptionLevel.Socket, 
+SocketOptionName.SendBuffer, 8192);
+socket.SetSocketOption(SocketOptionLevel.Socket, 
+SocketOptionName.ReceiveBuffer, 8192);
+AsyncCallback onconnect = new AsyncCallback(OnConnect);
+socket.BeginConnect(server, onconnect, socket);
+
+private void OnConnect(IAsyncResult ar) {
+  Socket socket = (Socket)ar.AsyncState;
+
+  if (socket.Connected) {
+    try {
+        socket.BeginSend(outgoingBytes, 0, outgoingBytes.Length,
+                    SocketFlags.None, new AsyncCallback(OnSentData), 
+socket);
+    } catch (SocketException se) {
+        Console.Err.WriteLine("Exception: " + se.ToString());
+        Cleanup(socket);
+    } 
+
+private void OnSentData(IAsyncResult ar) {
+    Socket socket = (Socket)ar.AsyncState;
+    try {
+        int n = socket.EndSend(ar);
+    } catch (SocketException se) {
+        Console.Err.WriteLine("Exception: " + se.ToString());
+        Cleanup(socket);
+    }
+
+
+Actual Results:
+
+Unhandled Exception: System.Net.Sockets.SocketException: Operation on non-
+blocking socket would block
+in (unmanaged) /usr/lib/libmono.so.0(mono_raise_exception+0x20) 
+[0x400aea94]
+in (unmanaged) /usr/lib/libmono.so.0 [0x400cc16d]
+in <0x000e8> System.Net.Sockets.Socket:Send (byte
+[],int,int,System.Net.Sockets.SocketFlags)
+in <0x00102> System.Net.Sockets.Socket:Send (byte
+[],int,int,System.Net.Sockets.SocketFlags)
+in <0x00056> .Worker:Send ()
+in <0x00044> (wrapper delegate-invoke) 
+System.MulticastDelegate:invoke_void ()
+
+Expected Results:
+No exception thrown.  Or SocketException thrown when socket.EndSend(ar) 
+is called to indicate WSAEWOULDBLOCK occurred.
+
+How often does this happen? 
+A couple of times per hour on a server that is not always active.
+
+Additional Information: