Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yyjdelete opened this issue Jan 14, 2022 · 0 comments

Comments

@yyjdelete
Copy link
Collaborator

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;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant