Netty 5.0.0 closeFuture().sync() 永远不会完成
Netty 5.0.0 closeFuture().sync() never finishing
我目前正在 Java 使用 Netty 编写程序,我偶然发现了以下问题:
每当我在 "bootstrap" 完成后尝试使用 channel#closeFuture().sync() 时,它永远不会完成任务并永远锁定主线程。不会抛出任何异常。
我的启动代码:
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup);
serverBootstrap.channel(NioServerSocketChannel.class);
serverBootstrap.childHandler(new IOLauncher());
this.channel = serverBootstrap.bind(8192).sync().channel();
System.out.println("Debug; closeFuture");
this.channel.closeFuture().sync(); // This never finishes!
System.out.println("Debug; closeFuture done");
} catch (Exception e) {
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
这是按预期工作的,closeFuture()
是一个将在频道关闭时完成的未来。这意味着如果通道没有关闭,未来将永远不会结束,sync()
将无限期阻塞。
已修复,完全没有问题,这对我来说是个愚蠢的问题。
我目前正在 Java 使用 Netty 编写程序,我偶然发现了以下问题:
每当我在 "bootstrap" 完成后尝试使用 channel#closeFuture().sync() 时,它永远不会完成任务并永远锁定主线程。不会抛出任何异常。
我的启动代码:
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup);
serverBootstrap.channel(NioServerSocketChannel.class);
serverBootstrap.childHandler(new IOLauncher());
this.channel = serverBootstrap.bind(8192).sync().channel();
System.out.println("Debug; closeFuture");
this.channel.closeFuture().sync(); // This never finishes!
System.out.println("Debug; closeFuture done");
} catch (Exception e) {
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
这是按预期工作的,closeFuture()
是一个将在频道关闭时完成的未来。这意味着如果通道没有关闭,未来将永远不会结束,sync()
将无限期阻塞。
已修复,完全没有问题,这对我来说是个愚蠢的问题。