From 6ed203b7baf4c5797a6692975059b05d26821402 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 11 Apr 2019 18:54:31 +0200 Subject: [PATCH] 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. --- .../socket/nio/NioServerSocketChannel.java | 4 +++- .../nio/NioServerSocketChannelTest.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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