Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

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

Description

@yyjdelete

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions