Com-AugustCellars / CoAP-CSharp

CoAP Implementation in C#
Other
41 stars 19 forks source link

example server crash on Visual Studio 2017 for Mac with Mono 5.4.0 #38

Closed Xdeon closed 7 years ago

Xdeon commented 7 years ago

Hi,

The attempt to run the CoAP.Server.NET45 project on Visual Studio for Mac community version with Mono 5.4.0.201 failed with following output:

mono_w32socket_convert_error: no translation into winsock error for (6) "Device not configured"
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Net.Sockets.Socket.IOControl_internal (intptr,int,byte[],byte[],int&) <0x00012>
  at System.Net.Sockets.Socket.IOControl_internal (System.Net.Sockets.SafeSocketHandle,int,byte[],byte[],int&) [0x0000a] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System/System.Net.Sockets/Socket.cs:2491
  at System.Net.Sockets.Socket.IOControl (int,byte[],byte[]) [0x00019] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System/System.Net.Sockets/Socket.cs:2476
  at Com.AugustCellars.CoAP.Channel.UDPChannel.SetupUDPSocket (System.Net.Sockets.AddressFamily,int) [0x0000b] in /Users/wilbur/WorkSpace/Github/CoAP-CSharp-orgin/CoAP-CSharp/CoAP.NET/Channel/UDPChannel.cs:324
  at Com.AugustCellars.CoAP.Channel.UDPChannel.Start () [0x0003d] in /Users/wilbur/WorkSpace/Github/CoAP-CSharp-orgin/CoAP-CSharp/CoAP.NET/Channel/UDPChannel.cs:109
  at Com.AugustCellars.CoAP.Net.CoAPEndPoint.Start () [0x00055] in /Users/wilbur/WorkSpace/Github/CoAP-CSharp-orgin/CoAP-CSharp/CoAP.NET/Net/CoAPEndPoint.cs:193
  at Com.AugustCellars.CoAP.Server.CoapServer.Start () [0x00052] in /Users/wilbur/WorkSpace/Github/CoAP-CSharp-orgin/CoAP-CSharp/CoAP.NET/Server/CoapServer.cs:242
  at Com.AugustCellars.CoAP.Examples.ExampleServer.Main (string[]) [0x000a1] in /Users/wilbur/WorkSpace/Github/CoAP-CSharp-orgin/CoAP-CSharp/CoAP.Example/CoAP.Server/ExampleServer.cs:25
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <3c793b753d784afa873fb9d1cd346433>:0

Native stacktrace:

    0   mono32                              0x000f9429 mono_handle_native_crash + 233
    1   mono32                              0x00159389 sigabrt_signal_handler + 153
    2   libsystem_platform.dylib            0xa776902b _sigtramp + 43
    3   ???                                 0xffffffff 0x0 + 4294967295
    4   libsystem_c.dylib                   0xa7593b2a abort + 133
    5   mono32                              0x002bf3f3 mono_log_write_logfile + 355
    6   mono32                              0x002ba2c1 structured_log_adapter + 33
    7   mono32                              0x002d6305 monoeg_g_log + 85
    8   mono32                              0x00163007 mono_w32socket_convert_error + 119
    9   mono32                              0x001648c3 mono_w32socket_ioctl + 451
    10  mono32                              0x001fa3e1 ves_icall_System_Net_Sockets_Socket_IOControl_internal + 193
    11  ???                                 0x04030354 0x0 + 67306324
    12  ???                                 0x04030218 0x0 + 67306008
    13  ???                                 0x04030038 0x0 + 67305528
    14  ???                                 0x040253ec 0x0 + 67261420
    15  ???                                 0x04024860 0x0 + 67258464
    16  ???                                 0x04022244 0x0 + 67248708
    17  ???                                 0x03d57c81 0x0 + 64322689
    18  ???                                 0x006d6af0 0x0 + 7170800
    19  ???                                 0x006d6fe7 0x0 + 7172071
    20  mono32                              0x0004fe25 mono_jit_runtime_invoke + 757
    21  mono32                              0x00242b81 do_runtime_invoke + 81
    22  mono32                              0x00245fb4 do_exec_main_checked + 132
    23  mono32                              0x00244d95 mono_runtime_run_main_checked + 69
    24  mono32                              0x000ba7aa mono_jit_exec + 314
    25  mono32                              0x000bd48b mono_main + 10251
    26  mono32                              0x0003e84a main + 266
    27  mono32                              0x0003e735 start + 53
    28  ???                                 0x00000004 0x0 + 4

Debug info from gdb:

(lldb) command source -s 0 '/tmp/mono-gdb-commands.0YCBcD'
Executing commands in '/tmp/mono-gdb-commands.0YCBcD'.
(lldb) process attach --pid 63850
Process 63850 stopped
* thread #1, name = 'tid_303', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0xa76446aa libsystem_kernel.dylib`__wait4 + 10
libsystem_kernel.dylib`__wait4:
->  0xa76446aa <+10>: jae    0xa76446ba                ; <+26>
    0xa76446ac <+12>: calll  0xa76446b1                ; <+17>
    0xa76446b1 <+17>: popl   %edx
    0xa76446b2 <+18>: movl   0x242d97b(%edx), %edx
Target 0: (mono32) stopped.

Executable module set to "/Library/Frameworks/Mono.framework/Versions/5.4.0/bin/mono32".
Architecture set to: i386-apple-macosx.
(lldb) thread list
Process 63850 stopped
* thread #1: tid = 0x69a7d2, 0xa76446aa libsystem_kernel.dylib`__wait4 + 10, name = 'tid_303', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  thread #2: tid = 0x69a800, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
  thread #3: tid = 0x69a801, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
  thread #4: tid = 0x69a805, 0xa763ad5e libsystem_kernel.dylib`semaphore_wait_trap + 10, name = 'Finalizer'
  thread #5: tid = 0x69a806, 0xa7643fca libsystem_kernel.dylib`__recvfrom + 10, name = 'Debugger agent'
  thread #6: tid = 0x69a823, 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #7: tid = 0x69a824, 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #8: tid = 0x69a825, 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #9: tid = 0x69a845, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'Timer-Scheduler'
  thread #10: tid = 0x69a846, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'tid_3403'
  thread #11: tid = 0x69a847, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'Threadpool worker'
  thread #12: tid = 0x69a848, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'tid_3a03'
  thread #13: tid = 0x69a849, 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'Threadpool worker'
(lldb) thread backtrace all
* thread #1, name = 'tid_303', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0xa76446aa libsystem_kernel.dylib`__wait4 + 10
    frame #1: 0xa75b0d4e libsystem_c.dylib`waitpid$UNIX2003 + 32
    frame #2: 0x000f94ec mono32`mono_handle_native_crash + 428
    frame #3: 0x00159389 mono32`sigabrt_signal_handler + 153
  thread #2, name = 'SGen worker'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7774140 libsystem_pthread.dylib`pthread_cond_wait$UNIX2003 + 51
    frame #3: 0x002b6672 mono32`thread_func + 738
    frame #4: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #5: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #6: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #3, name = 'SGen worker'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7774140 libsystem_pthread.dylib`pthread_cond_wait$UNIX2003 + 51
    frame #3: 0x002b6654 mono32`thread_func + 708
    frame #4: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #5: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #6: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #4, name = 'Finalizer'
    frame #0: 0xa763ad5e libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #1: 0x0023ab83 mono32`finalizer_thread + 339
    frame #2: 0x0020e055 mono32`start_wrapper + 661
    frame #3: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #4: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #5: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #5, name = 'Debugger agent'
    frame #0: 0xa7643fca libsystem_kernel.dylib`__recvfrom + 10
    frame #1: 0xa75b0f2c libsystem_c.dylib`recv$UNIX2003 + 30
    frame #2: 0x00132c19 mono32`socket_transport_recv + 73
    frame #3: 0x0011e5b4 mono32`debugger_thread + 1332
    frame #4: 0x0020e055 mono32`start_wrapper + 661
    frame #5: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #6: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #7: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #6
    frame #0: 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa77710a0 libsystem_pthread.dylib`_pthread_wqthread + 1536
    frame #2: 0xa7770a7a libsystem_pthread.dylib`start_wqthread + 34
  thread #7
    frame #0: 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa7770eab libsystem_pthread.dylib`_pthread_wqthread + 1035
    frame #2: 0xa7770a7a libsystem_pthread.dylib`start_wqthread + 34
  thread #8
    frame #0: 0xa764471a libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa77710a0 libsystem_pthread.dylib`_pthread_wqthread + 1536
    frame #2: 0xa7770a7a libsystem_pthread.dylib`start_wqthread + 34
  thread #9, name = 'Timer-Scheduler'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7777545 libsystem_pthread.dylib`pthread_cond_timedwait$UNIX2003 + 52
    frame #3: 0x00230154 mono32`mono_os_cond_timedwait + 132
    frame #4: 0x0022ed82 mono32`mono_w32handle_timedwait_signal_handle + 226
    frame #5: 0x0022ec10 mono32`mono_w32handle_wait_one + 848
    frame #6: 0x0022eef8 mono32`mono_w32handle_wait_multiple + 200
    frame #7: 0x00208a6c mono32`mono_wait_uninterrupted + 140
    frame #8: 0x00208d50 mono32`ves_icall_System_Threading_WaitHandle_WaitOne_internal + 112
    frame #9: 0x03d5c330
    frame #10: 0x03d5c00c
    frame #11: 0x03d5bc4c
    frame #12: 0x03d5b6b0
    frame #13: 0x03d5b5a0
    frame #14: 0x03d5b49c
    frame #15: 0x03d55fa9
    frame #16: 0x03d54337
    frame #17: 0x03d536b0
    frame #18: 0x03d5333c
    frame #19: 0x03d52de4
    frame #20: 0x03d52c24
    frame #21: 0x0216f16d
    frame #22: 0x0004fe25 mono32`mono_jit_runtime_invoke + 757
    frame #23: 0x00242b81 mono32`do_runtime_invoke + 81
    frame #24: 0x0024446d mono32`mono_runtime_delegate_try_invoke + 269
    frame #25: 0x0024449f mono32`mono_runtime_delegate_invoke_checked + 31
    frame #26: 0x0020e07e mono32`start_wrapper + 702
    frame #27: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #28: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #29: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #10, name = 'tid_3403'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7777545 libsystem_pthread.dylib`pthread_cond_timedwait$UNIX2003 + 52
    frame #3: 0x002cc1da mono32`mono_thread_info_sleep + 826
    frame #4: 0x00212fb4 mono32`monitor_thread + 1092
    frame #5: 0x0020e055 mono32`start_wrapper + 661
    frame #6: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #7: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #8: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #11, name = 'Threadpool worker'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7777545 libsystem_pthread.dylib`pthread_cond_timedwait$UNIX2003 + 52
    frame #3: 0x002135ec mono32`worker_thread + 940
    frame #4: 0x0020e055 mono32`start_wrapper + 661
    frame #5: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #6: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #7: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #12, name = 'tid_3a03'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7777545 libsystem_pthread.dylib`pthread_cond_timedwait$UNIX2003 + 52
    frame #3: 0x002135ec mono32`worker_thread + 940
    frame #4: 0x0020e055 mono32`start_wrapper + 661
    frame #5: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #6: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #7: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
  thread #13, name = 'Threadpool worker'
    frame #0: 0xa7643d6e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa77724eb libsystem_pthread.dylib`_pthread_cond_wait + 658
    frame #2: 0xa7777545 libsystem_pthread.dylib`pthread_cond_timedwait$UNIX2003 + 52
    frame #3: 0x002135ec mono32`worker_thread + 940
    frame #4: 0x0020e055 mono32`start_wrapper + 661
    frame #5: 0xa777151d libsystem_pthread.dylib`_pthread_body + 347
    frame #6: 0xa77713c2 libsystem_pthread.dylib`_pthread_start + 357
    frame #7: 0xa7770a9e libsystem_pthread.dylib`thread_start + 34
(lldb) detach

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

Process 63850 detached
(lldb) quit

This seems to work on Mono 4.8, but if one would like to use this library in a Xamarin iOS project than there is no obvious way of changing the underlying building environment.

It will be very appreciated if you could give some hints on how to fix this.

Thank you.

Best regards

jimsch commented 7 years ago

Wish I could debug this, but I don't have a MAC.

Two things to try:

  1. Change line 324 of UDPChannel.cs to "socket.Socket.IOControl(SIO_UDP_CONNRESET, new byte[4]{0}, null);" The problem may be that the value is not long enough. I would be surprised if that was the problem however.
  2. Just comment out the line, the code expects that it should be throwing an exception in this case and is coded defensively to prevent that from being a problem. This does not seem to be running correctly with your version of mono.
jimsch commented 7 years ago

It seems to run file on 5.2.0.224 on a linux system based on travis-cl logs.

Xdeon commented 7 years ago

Thanks a lot for such a quick reply!

It turns out the first solution makes no difference, but commenting out this line solved the problem.

I guess this may be a Mac specific problem. Anyway, thank you again for your help.

jimsch commented 7 years ago

should now be fixed