cuteant / SpanNetty

Port of Netty(v4.1.51.Final) for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncatched RejectedExecutionException on IOCP thread will crash the whole app after eventloop is stopped

yyjdelete opened this issue · comments

Unlike DotNetty, SpanNetty will throw RejectedExecutionException when try to submit to a eventloop after it's stopped.
But unluckly it's not catched on callback of IOCP, then it will leak to threadpool, and crashes the whole app.
(You can close all connected channel before close eventloop. But for connecting channel you can't do anything before it's timeout (if the dest is unavailable))

static void OnIoCompleted(object sender, SocketAsyncEventArgs args)
{
var operation = (SocketChannelAsyncOperation<TChannel, TUnsafe>)args;
var channel = operation.Channel;
var @unsafe = channel.Unsafe;
IEventLoop eventLoop = channel.EventLoop;
switch (args.LastOperation)
{
case SocketAsyncOperation.Accept:
if (eventLoop.InEventLoop)
{
@unsafe.FinishRead(operation);
}
else
{
eventLoop.Execute(ReadCallbackAction, @unsafe, operation);
}
break;
case SocketAsyncOperation.Connect:
if (eventLoop.InEventLoop)
{
@unsafe.FinishConnect(operation);
}
else
{
eventLoop.Execute(ConnectCallbackAction, @unsafe, operation);
}
break;
case SocketAsyncOperation.Receive:
case SocketAsyncOperation.ReceiveFrom:
if (eventLoop.InEventLoop)
{
@unsafe.FinishRead(operation);
}
else
{
eventLoop.Execute(ReadCallbackAction, @unsafe, operation);
}
break;
case SocketAsyncOperation.Send:
case SocketAsyncOperation.SendTo:
if (eventLoop.InEventLoop)
{
@unsafe.FinishWrite(operation);
}
else
{
eventLoop.Execute(WriteCallbackAction, @unsafe, operation);
}
break;
default:
// todo: think of a better way to comm exception
ThrowHelper.ThrowArgumentException_TheLastOpCompleted(); break;
}
}