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
e00e06c037
commit
806dace32d
@ -117,7 +117,9 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
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
|
@Override
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel.socket.nio;
|
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.EventLoopGroup;
|
||||||
import io.netty.channel.MultithreadEventLoopGroup;
|
import io.netty.channel.MultithreadEventLoopGroup;
|
||||||
import io.netty.channel.nio.NioHandler;
|
import io.netty.channel.nio.NioHandler;
|
||||||
@ -47,6 +49,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
|
@Override
|
||||||
protected NioServerSocketChannel newNioChannel(EventLoopGroup group) {
|
protected NioServerSocketChannel newNioChannel(EventLoopGroup group) {
|
||||||
return new NioServerSocketChannel(group.next(), group);
|
return new NioServerSocketChannel(group.next(), group);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user