NioServerSocketChannel.isActive() must return false after close() completes. (#9030)
Motivation: When a Channel was closed its isActive() method must return false. Modifications: First check for isOpen() before isBound() as isBound() will continue to return true even after the underyling fd was closed. Result: Fixes https://github.com/netty/netty/issues/9026.
This commit is contained in:
parent
6278d09139
commit
6ed203b7ba
@ -106,7 +106,9 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return javaChannel().socket().isBound();
|
||||
// As java.nio.ServerSocketChannel.isBound() will continue to return true even after the channel was closed
|
||||
// we will also need to check if it is open.
|
||||
return isOpen() && javaChannel().socket().isBound();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package io.netty.channel.socket.nio;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import org.junit.Assert;
|
||||
@ -45,6 +47,23 @@ public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServer
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsActiveFalseAfterClose() {
|
||||
NioServerSocketChannel serverSocketChannel = new NioServerSocketChannel();
|
||||
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||
try {
|
||||
group.register(serverSocketChannel).syncUninterruptibly();
|
||||
Channel channel = serverSocketChannel.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
||||
Assert.assertTrue(channel.isActive());
|
||||
Assert.assertTrue(channel.isOpen());
|
||||
channel.close().syncUninterruptibly();
|
||||
Assert.assertFalse(channel.isOpen());
|
||||
Assert.assertFalse(channel.isActive());
|
||||
} finally {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NioServerSocketChannel newNioChannel() {
|
||||
return new NioServerSocketChannel();
|
||||
|
Loading…
Reference in New Issue
Block a user