diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java index 128e531e56..556549a62c 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java @@ -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 diff --git a/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java b/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java index ec50223977..1292220aaa 100644 --- a/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java +++ b/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java @@ -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