mirror of
https://github.com/layue13/MoonBridge.git
synced 2026-10-25 18:46:18 +00:00
fix: 关闭监听器时同时关闭 boss 与 worker 事件循环
ProxySessionListener.close() 原先等 boss 组 shutdownGracefully 完成后才开始关闭 worker 组。两组各自要等 2 秒静默期,所以每次 close 至少约 4 秒。测试用 close().get(5, SECONDS) 收尾,在较慢的 Gitea runner 上 SessionTransferTest 有两个 用例因此超时(run 14129);本机 SessionTransferTest 每个用例也都在 4.16 秒以上,最慢 5.18 秒。 改为同时开始关闭两组,两者都结束后再完成 shutdown。各组仍保留默认静默期,关闭前已 提交的任务照常执行。本机 SessionTransferTest 单用例中位数 4.19 秒降到 2.15 秒,最慢 5.18 秒降到 3.13 秒。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ae0af8bae
commit
39e7f11a96
1 file changed
+5
-1
@@ -34,6 +34,7 @@ import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.resolver.AddressResolverGroup;
|
||||
import io.netty.resolver.dns.DnsAddressResolverGroup;
|
||||
import io.netty.resolver.dns.DnsNameResolverBuilder;
|
||||
import io.netty.util.concurrent.Future;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
@@ -512,7 +513,10 @@ public final class ProxySessionListener implements Players {
|
||||
allSessions.forEach(session -> session.closeBecause("proxy shutting down"));
|
||||
backendResolver.close();
|
||||
shutdown = new CompletableFuture<>();
|
||||
boss.shutdownGracefully().addListener(first -> workers.shutdownGracefully().addListener(second -> {
|
||||
// Start both at once: each group waits out its own quiet period, so draining them in turn doubled the close time.
|
||||
Future<?> bossStopped = boss.shutdownGracefully();
|
||||
Future<?> workersStopped = workers.shutdownGracefully();
|
||||
bossStopped.addListener(first -> workersStopped.addListener(second -> {
|
||||
if (first.isSuccess() && second.isSuccess()) shutdown.complete(null);
|
||||
else shutdown.completeExceptionally(first.isSuccess() ? second.cause() : first.cause());
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user