From dab20ccdb64f30177e97d0281ee91bff23c92c15 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 27 Aug 2015 10:29:19 +0200 Subject: [PATCH] Only try to obtain SO_LINGER on close if fd is still open. Motivation: When try to get SO_LINGER from a fd that is closed an Exception is thrown. We should only try to get SO_LINGER if the fd is still open otherwise an Exception is thrown that can be ignored anyway. Modifications: First check if the fd is still open before try to obtain SO_LINGER setting when get the closeExecutor. This is also the same that we do in the NIO transport. Result: No more exception when calling unsafe.close() on a channel that has a closed file descriptor. --- .../main/java/io/netty/channel/epoll/EpollSocketChannel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java index 39bb0e0577..3ddf6aed2a 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java @@ -197,7 +197,9 @@ public final class EpollSocketChannel extends AbstractEpollStreamChannel impleme private final class EpollSocketChannelUnsafe extends EpollStreamUnsafe { @Override protected Executor closeExecutor() { - if (config().getSoLinger() > 0) { + // Check isOpen() first as otherwise it will throw a RuntimeException + // when call getSoLinger() as the fd is not valid anymore. + if (isOpen() && config().getSoLinger() > 0) { return GlobalEventExecutor.INSTANCE; } return null;