Mina.NET icon indicating copy to clipboard operation
Mina.NET copied to clipboard

Potential inconsistency in the pool of SocketAsyncEventArgs will cause InvalidOperationException when try to start a session

Open longshine opened this issue 11 years ago • 0 comments

Problem

The AsyncSocketAcceptor (for .NET 4.0) listens to the SessionDestroyed event of a session, and returns its buffers for reading and writing to the buffer pool for reuse when it has been destroyed. This is how the reusable SocketAsyncEventArgs works, and it works fine, most time.

Normally the SessionDestroyed event will be fired after the socket closes. However, since the socket is working asynchronously, the close operation may have not completely been done until some time later. Hence, the buffers returned to the pool may still be in use, making it inconsistent. If a newly accepted session accquires one of those buffers and tries to begin receiving operation on it, it will throw a InvalidOperationException saying "A socket operation was already in progress".

Although the receiving operation will be started again even an exception occurs, this may be severe in high-load environment.

Backward compatibility

No backward compatibility problems are expected.

longshine avatar Nov 07 '14 09:11 longshine