ShutdownGracefullyAsync of MultithreadEventLoopGroup takes 100ms at minimum
- Dominant language
- C#
- Stars
- 4.3k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
When looking into issue why client disconnections are taking longer than expected I came across the code in SingleThreadEventExecutor which is very similar to the original Netty code:
~~~
if (nanoTime - this.lastExecutionTime <= this.gracefulShutdownQuietPeriod)
{
// Check if any tasks were added to the queue every 100ms.
// TODO: Change the behavior of takeTask() so that it returns on timeout.
// todo: ???
this.WakeUp(true);
Thread.Sleep(100);
return false;
}
// No tasks were added for last quiet period - hopefully safe to shut down.
// (Hopefully because we really cannot make a guarantee that there will be no execute() calls by a user.)
return true;
~~~
This has side effect of ShutdownGracefullyAsync taking at least 100ms regardless of timeout period.
Additionally, the shutdown lasts always for whole timeout period in our case.
Observing the inner loops in the library, there is 'noop' incoming periodically triggering the quiet period restart every time.

Contributor guide
Assessment
This issue has not been assessed yet.