kerryjiang / WebSocket4Net

A popular .NET WebSocket Client
Apache License 2.0
764 stars 273 forks source link

IndexOutOfRangeException in WebSocket4Net.Protocol.WebSocketDataFrame.get_FIN() #98

Open jbrestan opened 7 years ago

jbrestan commented 7 years ago

Hi,

it happend a few times, non-deterministically, that receiving a message resulted in an unhandled IndexOutOfRange exception, killing my process without being able to catch it.

The WebSocket4Net version I use is 0.14.1, it's used against https://github.com/SuaveIO/suave version 1.1.3

This is the full exception stack

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SuperSocket.ClientEngine.Protocol.ArraySegmentList`1.get_Item(Int32 index)
   at WebSocket4Net.Protocol.WebSocketDataFrame.get_FIN()
   at WebSocket4Net.Protocol.DraftHybi10DataReader.GetCommandInfo(Byte[] readBuffer, Int32 offset, Int32 length, Int32& left)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
   at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted(Object sender, SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object ignored)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
   at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

I will post more info if I'm able to collect it - it happened only twice, not during debugging or sniffing the communication, so the exception is the only thing I currently have.

Does anyone know what scenario can cause this, and whether it's possible to handle the exception somewhere so that my process won't have to crash?

Thank you!