From 960a486f13c6101ed76dfb99959501995697a01e Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 23 Feb 2015 19:01:32 +0100 Subject: [PATCH] [#3443] Fix IllegalStateException which could be triggered when the channel goes inactive during the eventloop processing Motivation: This is a regression that was introduced as part of 6b941e9bdbc1b1a9090c280bc6c44903ff7c7b67. The regression could produce an "infinity" triggering of IllegalStateException if a channel goes inactive while process the events for it. Modifications: Correctly check if the channel is still active before trigger the callbacks. Result: No more IllegalStateException --- .../io/netty/channel/epoll/EpollEventLoop.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java index 16707ea7b9..7911af5681 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java @@ -310,17 +310,24 @@ final class EpollEventLoop extends SingleThreadEventLoop { boolean write = (ev & Native.EPOLLOUT) != 0; AbstractEpollUnsafe unsafe = (AbstractEpollUnsafe) ch.unsafe(); - if (write) { + + if (close) { + unsafe.epollRdHupReady(); + } + + // We need to check if the channel is still open before try to trigger the + // callbacks as otherwise we may trigger an IllegalStateException when try + // to access the file descriptor. + // + // See https://github.com/netty/netty/issues/3443 + if (write && ch.isOpen()) { // force flush of data as the epoll is writable again unsafe.epollOutReady(); } - if (read) { + if (read && ch.isOpen()) { // Something is ready to read, so consume it now unsafe.epollInReady(); } - if (close) { - unsafe.epollRdHupReady(); - } } else { // We received an event for an fd which we not use anymore. Remove it from the epoll_event set. Native.epollCtlDel(epollFd, fd);