[Mono-dev] Asynchronous socket segmentation fault continued

Robert Nasiadek robzon at cpnet.pl
Tue Feb 14 21:12:18 EST 2006


Here's a simple code that causes segmentation fault:

--- CUT HERE ---
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;

class Test
{
        Socket          sock1;
        Socket          sock2;
        byte[]          data;
        EndPoint        remote1;
        EndPoint        remote2;

        static void Main( )
        {
                Test t = new Test( );
                t.Run( );
        }

        void Run( )
        {
                sock1 = new Socket( AddressFamily.InterNetwork, 
SocketType.Dgram, ProtocolType.Udp );
                sock2 = new Socket( AddressFamily.InterNetwork, 
SocketType.Dgram, ProtocolType.Udp );
                remote1 = new IPEndPoint( IPAddress.Any, 0 );
                remote2 = new IPEndPoint( IPAddress.Any, 0 );

                IPEndPoint local1 = new IPEndPoint( IPAddress.Any, 1024 );
                IPEndPoint local2 = new IPEndPoint( IPAddress.Any, 1025 );
                sock1.Bind( local1 );
                sock2.Bind( local2 );

                data = new byte[32];
                sock1.BeginReceiveFrom( data, 0, 16, SocketFlags.None, 
ref remote1, new AsyncCallback( OnRecv1 ), null );
                sock2.BeginReceiveFrom( data, 16, 16, SocketFlags.None, 
ref remote2, new AsyncCallback( OnRecv2 ), null );

                Thread.Sleep( 20000 );
        }

        void OnRecv1( IAsyncResult ar )
        {
                Console.WriteLine( "sock1.EndReceiveFrom( )" );
                sock1.EndReceiveFrom( ar, ref remote1 );
                Console.WriteLine( "sock2.Close( )" );
                sock2.Close( );
        }
        void OnRecv2( IAsyncResult ar )
        {
                Console.WriteLine( "sock2.EndReceiveFrom( )" );
                sock2.EndReceiveFrom( ar, ref remote2 );
                Console.WriteLine( "sock1.Close( )" );
                sock1.Close( );
        }
}
--- CUT HERE ---

After running this code I just send a UDP packet to port 1024 (echo a | 
nc -u localhost 1024).
On mono 1.1.13.2 (Linux) I get:

sock1.EndReceiveFrom( )
sock2.Close( )

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Stacktrace:

in <0x4> (wrapper managed-to-native) 
System.Net.Sockets.Socket:RecvFrom_internal 
(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)
in <0xffffff7b> (wrapper managed-to-native) 
System.Net.Sockets.Socket:RecvFrom_internal 
(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)
in <0x4b> System.Net.Sockets.Socket:ReceiveFrom_nochecks 
(byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.EndPoint&)
in <0x5b> Worker:ReceiveFrom ()
in <0xffffff90> (wrapper delegate-invoke) 
System.MulticastDelegate:invoke_void ()
in <0x50ee921f> (wrapper runtime-invoke) 
System.Object:runtime_invoke_void (object,intptr,intptr,intptr)

Native stacktrace:

        mono(mono_handle_native_sigsegv+0xba) [0x814c43a]
        mono [0x813890f]
        [0xffffe440]
        mono [0x80b9719]
        [0xb724f866]
        [0xb724f7ac]
        [0xb724f6dc]
        [0xb724f668]
        [0xb724f5c9]
        mono [0x81387c0]
        mono(mono_runtime_invoke+0x27) [0x80d5067]
        mono(mono_runtime_invoke_array+0x250) [0x80d6510]
        mono(mono_message_invoke+0xc5) [0x80d7fc5]
        mono [0x80a423f]
        mono [0x80a32d3]
        mono [0x8099282]
        mono [0x8104bc7]
        mono [0x8110805]
        /lib/tls/i686/cmov/libpthread.so.0 [0xb7e3e361]
        /lib/tls/i686/cmov/libc.so.6(__clone+0x5e) [0xb7da8bde]

On .net on Windows I get:

sock1.EndReceiveFrom( )
sock2.Close( )
sock2.EndReceiveFrom( )

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.EndReceiveFrom(IAsyncResult asyncResult, 
EndPoint& endPoint)
   at Test.OnRecv2(IAsyncResult ar)
   at 
System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32 
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped


peace,

-- 
robzon
Network Administrator

[ http://ubuntu.com/ ]
_____________________
(\ /)
(O.o)
(> <)
This is Bunny. Copy Bunny into your signature to help him on his way to world domination.




More information about the Mono-devel-list mailing list