clj-commons / aleph

Asynchronous streaming communication for Clojure - web server, web client, and raw TCP/UDP
http://aleph.io
MIT License
2.54k stars 241 forks source link

Support graceful shutdown with ChannelGroup #641

Closed arnaudgeiser closed 2 years ago

arnaudgeiser commented 2 years ago

Description

This PR is an attempt to address #638 where we noticed that EventLoopGroup#shutdownGracefully timeouts are not waiting for active connections but is closing all the EventExecutor right away. [1] It's not an issue on the Netty side but an expected behaviour. [2]

Still, people using a shutdown-timeout would expect active connections to be finished before shutting down the server. The proposition is to track all Channel on an ChannelGroup [3], and wait for them to be closed before shutting down the server. This use case is mentioned on the ChannelGroup Java documentation.

Open questions

Let's keep the current behavior when shutdown-timeout is not explicitly set.

[1] : https://github.com/netty/netty/blob/4.1/transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java#L420 [2] : https://github.com/netty/netty/pull/3706#issuecomment-1303066857 [3] : https://netty.io/4.0/api/io/netty/channel/group/ChannelGroup.html

arnaudgeiser commented 2 years ago

Closing this PR in favor of another that will come soon.