GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Why can't I shutdown the Netty Client ? · Issue #7694 · netty/netty Closed DescriptionExpected behaviorI have launched a netty server and establish a connection with it via netty client. The client sends a message to the server, while the server will feedback and close context (Channel), when the client got a message from the server, it will close channel and shutdown EventLoopGroup, and then exit the program. Actual behaviorHowever, all the channel was closed, but the EventLoopGroup unable to shutdown (isShutdown always false), no matter client or server, the main thread blocked. Steps to reproduceThe code as follow. Minimal yet complete reproducer code (or URL to code)
import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.Delimiters; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.util.ReferenceCountUtil; public class TestServer { public static final int PORT = 12345; public static void main(String[] args) throws InterruptedException { ServerBootstrap bootstrap = new ServerBootstrap(); NioEventLoopGroup bossGroup = new NioEventLoopGroup(1); NioEventLoopGroup workerGroup = new NioEventLoopGroup(1); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new Initializer()); ChannelFuture future = bootstrap.bind(PORT).sync(); future.channel().closeFuture().sync(); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } static class Initializer extends ChannelInitializer<SocketChannel> { private static final StringDecoder DECODER = new StringDecoder(); private static final StringEncoder ENCODER = new StringEncoder(); @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); pipeline.addLast(new Handler()); } } static class Handler extends SimpleChannelInboundHandler<String> { @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { System.out.println("server:" + msg); ctx.writeAndFlush(msg + "\r\n"); ReferenceCountUtil.release(msg); ctx.close(); } } }
import io.netty.bootstrap.Bootstrap; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.Delimiters; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.util.ReferenceCountUtil; public class TestClient { public static void main(String[] args) throws InterruptedException { Bootstrap bootstrap = new Bootstrap(); EventLoopGroup group = new NioEventLoopGroup(1); ChannelFuture future = bootstrap.group(group) .handler(new Initializer()) .option(ChannelOption.SO_KEEPALIVE, true) .channel(NioSocketChannel.class) .connect("127.0.0.1", TestServer.PORT); future.sync().channel().writeAndFlush("abcdef\r\n"); future.channel().closeFuture().sync(); group.shutdownGracefully(); System.out.println("closed: " + !future.channel().isOpen() + "/shutdown:" + group.isShutdown()); } static class Initializer extends ChannelInitializer<SocketChannel> { private static final StringDecoder DECODER = new StringDecoder(); private static final StringEncoder ENCODER = new StringEncoder(); @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); pipeline.addLast(new Handler()); } } static class Handler extends SimpleChannelInboundHandler<String> { @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { System.out.println("client:" + msg); ctx.writeAndFlush(msg); ReferenceCountUtil.release(msg); ctx.close(); } } } Netty version<dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.20.Final</version> </dependency> JVM version (e.g.
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |