ServerSocketChannel state after disconnect() or close()

13 views
Skip to first unread message

Priyanka Perera

unread,
Apr 11, 2019, 8:11:54 AM4/11/19
to ne...@googlegroups.com
Hi all,

What's the expected state of a server socket channel once the close() or disconnect() is invoked ?

Below code reports that server socket channel is still active even after the close() future is sync'ed.
final EchoServerHandler serverHandler = new EchoServerHandler();
EventLoopGroup group = new NioEventLoopGroup();
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(group)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>(){
@Override
public void initChannel(SocketChannel ch)
throws Exception {
ch.pipeline().addLast(serverHandler);
}
});

ChannelFuture channelFuture = serverBootstrap.bind().sync();
System.out.println("Server started");
Thread.sleep(5000);
Assert.assertTrue(channelFuture.channel().close().sync().isSuccess());
Assert.assertFalse(channelFuture.channel().isActive(), "Channel is active");

It fails on the last assertion with

Exception in thread "Thread-0" java.lang.AssertionError: Channel is active expected [false] but found [true]
    at org.testng.Assert.fail(Assert.java:94)
    at org.testng.Assert.failNotEquals(Assert.java:513)
    at org.testng.Assert.assertFalse(Assert.java:63)
    at EchoServer.start(EchoServer.java:43)

    at ServerStarter.run(NettyTest.java:21)
    at java.lang.Thread.run(Thread.java:748)


What's the rational behind it ?

Thanks
Priyanka

Norman Maurer

unread,
Apr 11, 2019, 8:34:26 AM4/11/19
to ne...@googlegroups.com
This is a bug… 

Just opened a PR to fix it:


Thanks!



--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/CAJt14FMPjfej0ShgoMpC_AUWYGVCdQNva4OjzHtPC6eQSKf__g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages