[Mono-bugs] [Bug 76249][Nor] New - Wrong exception for certain
Socket calls when Socket has been disposed
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Sep 27 13:27:18 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 jlarimer at gmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=76249
--- shadow/76249 2005-09-27 13:27:17.000000000 -0400
+++ shadow/76249.tmp.15719 2005-09-27 13:27:17.000000000 -0400
@@ -0,0 +1,102 @@
+Bug#: 76249
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details: Tested on Fedora Core 4
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: jlarimer at gmail.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Wrong exception for certain Socket calls when Socket has been disposed
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+When a Socket is closed, any attempt to perform operations on it should
+generate a System.ObjectDisposedException. Currently, there are some calls
+in Socket.cs that don't check for disposal and generate a
+System.NullReferenceException. Also, the behavior causes various problems
+debugging with gdb since a SIGSEGV happens.
+
+> Steps to reproduce the problem:
+1. Compile this as socktest.exe:
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+class socketest {
+ static void Main(string[] args) {
+ Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
+ProtocolType.Udp);
+
+ byte[] buf = new byte[100];
+ EndPoint ep = new IPEndPoint(IPAddress.Any, 31337);
+ s.Close();
+
+ s.ReceiveFrom(buf, ref ep);
+ }
+}
+
+2. Run under Microsoft.NET, the exception thrown is:
+
+Unhandled Exception: System.ObjectDisposedException: Cannot access a
+disposed object named "System.Net.Sockets.Socket".
+Object name: "System.Net.Sockets.Socket".
+ at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 offset,
+Int32 size, SocketFlags socketFlags, EndPoint& remoteEP)
+ at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, EndPoint& remoteEP)
+ at socketest.Main(String[] args) in c:\projects\socktest\class1.cs:line 13
+
+3. Run under Mono, the Exception thrown is:
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in <0x00000> <unknown method>
+in (wrapper managed-to-native) System.Net.Sockets.Socket:RecvFrom_internal
+(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)
+in <0x0004b> System.Net.Sockets.Socket:ReceiveFrom_nochecks (System.Byte[]
+buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint
+remote_end)
+in <0x0002c> System.Net.Sockets.Socket:ReceiveFrom (System.Byte[] buf,
+System.Net.EndPoint remote_end)
+in <0x0007d> socktest.Class1:Main (System.String[] args)
+
+4. In GDB, this happens:
+
+Program received signal SIGSEGV, Segmentation fault.
+[Switching to Thread -1209063744 (LWP 28173)]
+0x08120c90 in _wapi_handle_type (handle=0xffffffff)
+ at ../../mono/io-layer/handles-private.h:114
+114 return(_WAPI_PRIVATE_HANDLES(idx).type);
+
+
+This is because the handle is -1 when _wapi_handle_type gets called. That
+code should probably never get called... Sockets.cs handles the case for
+disposed sockets for some methods, but not others.
+
+
+> How often does this happen?
+
+Every time
+
+> Additional Information:
+
+Propsed patch attached. After applying the patch, the results are as expected:
+
+Unhandled Exception: System.ObjectDisposedException: The object was used
+after being disposed.
+in [0x0005a] (at
+/home/jlarimer/mono-dev/mcs/class/System/System.Net.Sockets/Socket.cs:1410)
+System.Net.Sockets.Socket:ReceiveFrom (System.Byte[] buf,
+System.Net.EndPoint remote_end)
+in [0x0002c] (at /home/jlarimer/test/socketest/socktest.cs:27)
+socktest.Class1:Main (System.String[] args)
More information about the mono-bugs
mailing list