From ff4a89b5ae315425ab3b462a21e8477aa64c8e9e Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 21 Apr 2014 11:16:07 +0200 Subject: [PATCH] [#2414] Fix RuntimeException during modify events via EpollEventLoop Motivation: We are currently try to modify the events via EpollEventLoop even when the channel was closed before and so the fd was set to -1. This fails with a RuntimeException in this case. Modification: Always check if the Channel is still open before try to modify the events. Result: No more RuntimeException because of a not open channel --- .../io/netty/channel/epoll/AbstractEpollChannel.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java index 02a7b4d317..54da0beef2 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java @@ -100,7 +100,7 @@ abstract class AbstractEpollChannel extends AbstractChannel { protected void doBeginRead() throws Exception { if ((flags & readFlag) == 0) { flags |= readFlag; - ((EpollEventLoop) eventLoop()).modify(this); + modifyEvents(); } } @@ -126,13 +126,19 @@ abstract class AbstractEpollChannel extends AbstractChannel { protected final void setEpollOut() { if ((flags & Native.EPOLLOUT) == 0) { flags |= Native.EPOLLOUT; - ((EpollEventLoop) eventLoop()).modify(this); + modifyEvents(); } } protected final void clearEpollOut() { if ((flags & Native.EPOLLOUT) != 0) { flags &= ~Native.EPOLLOUT; + modifyEvents(); + } + } + + private void modifyEvents() { + if (isOpen()) { ((EpollEventLoop) eventLoop()).modify(this); } } @@ -200,7 +206,7 @@ abstract class AbstractEpollChannel extends AbstractChannel { protected final void clearEpollIn0() { if ((flags & readFlag) != 0) { flags &= ~readFlag; - ((EpollEventLoop) eventLoop()).modify(AbstractEpollChannel.this); + modifyEvents(); } } }