[Mono-bugs] [Bug 75705][Nor] New - Receive on closed socket behaviour different between windows and linux.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Aug 3 23:14:19 EDT 2005


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 nev at delap.com.

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

--- shadow/75705	2005-08-03 23:14:19.000000000 -0400
+++ shadow/75705.tmp.32487	2005-08-03 23:14:19.000000000 -0400
@@ -0,0 +1,106 @@
+Bug#: 75705
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Windows-XP-5.1.2600 & Linux-2.6.8-2-k7-i686-with-debian-3.1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: Nev at Delap.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Receive on closed socket behaviour different between windows and linux.
+
+(Actually it's System.Net.Socket)
+
+Description of Problem:
+
+This particular behaviour of sockets is the same on MS.NET and Mono on 
+Windows, but different on Mono on Linux -
+A Receive() call on a socket throws when the socket is closed on MS.NET 
+and Mono on Windows. On Mono on Linux it does not, it throws later when 
+the app is being cleaned up I guess.
+
+Steps to reproduce the problem:
+
+The test fixture shows a difference in behaviour of sockets between 
+MS.NET and Mono on Windows, and Mono on Linux.
+
+    [TestFixture]
+    public class PlatformTest
+    {
+        protected bool   socketThreadRunning;
+        protected Socket socket;
+
+        [Test]
+#if CompactFramework
+        [Ignore("Test not supported in this build.")]
+#endif
+        public void CloseDiscoverySocketWhileAThreadIsReadingIt()
+        {
+            // Opening socket like discovery does.
+            socket = new Socket(AddressFamily.InterNetwork,  
+SocketType.Dgram, ProtocolType.Udp);
+            socket.SetSocketOption(SocketOptionLevel.Socket, 
+SocketOptionName.ReuseAddress, 1);
+            socket.Bind(new IPEndPoint(IPAddress.Any, 2917));
+            socket.SetSocketOption(SocketOptionLevel.IP, 
+SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse
+("224.4.0.1"), IPAddress.Any));
+            
+            Thread socketThread = new Thread(new ThreadStart
+(SocketThreadMethod));
+            socketThread         .Start();
+            socketThreadRunning = true;
+            Thread.Sleep(50); // Give the thread a moment to be in it's 
+socket.Receive() call.
+            socket.Close();
+            Thread.Sleep(50);  // Give it a moment to end.
+//#if !Linux
+//            Assert.IsFalse(socketThreadRunning);
+//#else
+//            Assert.IsTrue(socketThreadRunning);
+//#endif
+            // Compiled With MS.NET 1.1 or Mono 1.1.8 on Windows the next 
+line prints 'socketThreadRunning = False'.
+            // Compiled Mono 1.1.8 on Linux it 
+prints 'socketThreadRunning = True'.
+            Console.WriteLine("socketThreadRunning = {0}", 
+socketThreadRunning);
+        }
+
+        public void SocketThreadMethod()
+        {
+            byte[] bytes = new byte[50];
+            try
+            {
+                // On MS.NET and Mono on Windows this call throws when 
+the socket is closed.
+                // On Mono on Linux it doesn't.
+                socket.Receive(bytes);
+            }
+            catch (SocketException)
+            {
+                socketThreadRunning = false;
+            }
+        }
+    }
+    
+Actual Results:
+    
+MS.NET and Mono on Windows print 'socketThreadRunning = False'.
+Mono on Linux prints 'socketThreadRunning = True'.
+    
+Expected Results:
+
+That the behaviour is the same in both cases, 
+preferably 'socketThreadRunning = False' I think.
+    
+How often does this happen? 
+
+100% reproducible.


More information about the mono-bugs mailing list