Olivine-Labs / Alchemy-Websockets-Example

An example application built using the Alchemy Websockets library
http://www.alchemywebsockets.com
36 stars 21 forks source link

Clean disconnect issue #2

Open katterfelto opened 11 years ago

katterfelto commented 11 years ago

I am trying to play with your example chat application. I'm running the server on ArchLinux using Mono/.Net 4.0 and for client browsers I've tried Qupzilla 1.4.3 (webkit v537.21) and Google Chrome (27.0.1453.94).

On the chat client web page when I click the disconnect button the server crashes with the following exception:

Unhandled Exception: System.ArgumentException: Buffer is empty Parameter name: buffers at System.Net.Sockets.Socket.Send (IList1 buffers, SocketFlags socketFlags, System.Net.Sockets.SocketError& errorCode) [0x00000] in <filename unknown>:0 at System.Net.Sockets.Socket.Send (IList1 buffers, SocketFlags socketFlags) [0x00000] in :0 at System.Net.Sockets.Socket+Worker.SendGeneric () [0x00000] in :0

When this happens the OnDisconnect function is obviously not called for the context. If I just close the tab displaying the chat client the disconnections is handled cleanly. The following call in the demo causes the problem, Am I missing something>

$('#disconnect').bind('click', function(e) {
  e.preventDefault();
  AlchemyChatServer.Stop();
});
durgacharanb commented 9 years ago

I too have the same problem. when ever you tried to call websocket.close() from a client, it throws error. Seeing the log I could trace that the error is thrown while simaphore is tried to release in ReceiveEventArgs_Completed event handler under else condition. Sample code below.

if (context.ReceivedByteCount > 0) { context.Handler.HandleRequest(context); context.ReceiveReady.Release(); StartReceive(context); } else { context.Disconnect(); context.ReceiveReady.Release(); }

06-23 16:01:58.748 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, condition ok' not met 06-23 16:01:58.748 E/mono-rt ( 5122): Stacktrace: 06-23 16:01:58.748 E/mono-rt ( 5122): 06-23 16:01:58.748 E/mono-rt ( 5122): at <unknown> <0xffffffff> 06-23 16:01:58.748 E/mono-rt ( 5122): at (wrapper managed-to-native) System.Threading.NativeEventCalls.SetEvent_internal (intptr) <IL 0x00021, 0xffffffff> 06-23 16:01:58.748 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5185 (xxxxpackage.namexxx) 06-23 16:01:58.748 E/mono-rt ( 5122): at System.Threading.EventWaitHandle.Set () <IL 0x00018, 0x000fb> 06-23 16:01:58.748 E/mono-rt ( 5122): at (wrapper remoting-invoke-with-check) System.Threading.EventWaitHandle.Set () <IL 0x00038, 0xffffffff> 06-23 16:01:58.748 E/mono-rt ( 5122): at System.Threading.SemaphoreSlim.Release (int) <IL 0x0005f, 0x001d7> 06-23 16:01:58.753 E/mono-rt ( 5122): at System.Threading.SemaphoreSlim.Release () <IL 0x00002, 0x00067> 06-23 16:01:58.753 E/mono-rt ( 5122): at Alchemy.WebSocketServer.ReceiveEventArgs_Completed (object,System.Net.Sockets.SocketAsyncEventArgs) [0x00077] in c:\Alchemy-Websockets-NetCookies\Alchemy-Websockets-NetCookies-master\src\Alchemy.NetCookies.Android\WebSocketServer.cs:331 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, conditionok' not met 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5222 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, condition ok' not met 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, conditionok' not met 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5241 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5221 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, condition ok' not met 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, conditionok' not met 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, condition ok' not met 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, conditionok' not met 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5240 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, condition ok' not met 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5245 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/ ( 5122): * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/io-layer/wthreads.c:93, conditionok' not met 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5248 (xxxxpackage.namexxx) 06-23 16:01:58.753 E/mono-rt ( 5122): at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs) <IL 0x0001c, 0x000cb> 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5242 (xxxxpackage.namexxx) 06-23 16:01:58.753 F/libc ( 5122): Fatal signal 6 (SIGABRT) at 0x00001402 (code=-6), thread 5246 (xxxxpackage.namexxx) 06-23 16:01:58.753 E/mono-rt ( 5122): at System.Net.Sockets.SocketAsyncEventArgs.ReceiveCallback (System.IAsyncResult) <IL 0x0003c, 0x00187> 06-23 16:01:58.753 E/mono-rt ( 5122): at System.Net.Sockets.SocketAsyncEventArgs.DispatcherCB (System.IAsyncResult) <IL 0x00039, 0x0019b> 06-23 16:01:58.753 E/mono-rt ( 5122): at (wrapper runtime-invoke) .runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 0xffffffff> 06-23 16:01:58.753 E/mono-rt ( 5122): 06-23 16:01:58.753 E/mono-rt ( 5122): ================================================================= 06-23 16:01:58.753 E/mono-rt ( 5122): Got a SIGSEGV while executing native code. This usually indicates 06-23 16:01:58.753 E/mono-rt ( 5122): a fatal error in the mono runtime or one of the native libraries 06-23 16:01:58.753 E/mono-rt ( 5122): used by your application. 06-23 16:01:58.753 E/mono-rt ( 5122): =================================================================

If you could fix this issue, plz post the solution.