kerryjiang / WebSocket4Net

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

Unhandled NullReferenceException in Sending_Completed #145

Open pvginkel opened 5 years ago

pvginkel commented 5 years ago

I got the following NullReferenceException:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at SuperSocket.ClientEngine.AsyncTcpSession.Sending_Completed(Object sender, SocketAsyncEventArgs e)
   at SuperSocket.ClientEngine.AsyncTcpSession.SendInternal(PosList`1 items)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   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)

My guess is this is actually coming from AsyncTcpSession.OnClosed() since Sending_Complete seems to do proper checking. Copying the fields in AsyncTcpSession.OnClosed() should fix this one.