[#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
This commit is contained in:
Norman Maurer 2015-02-23 19:01:32 +01:00
parent c21067aab6
commit 960a486f13

View File

@ -310,17 +310,24 @@ final class EpollEventLoop extends SingleThreadEventLoop {
boolean write = (ev & Native.EPOLLOUT) != 0; boolean write = (ev & Native.EPOLLOUT) != 0;
AbstractEpollUnsafe unsafe = (AbstractEpollUnsafe) ch.unsafe(); 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 // force flush of data as the epoll is writable again
unsafe.epollOutReady(); unsafe.epollOutReady();
} }
if (read) { if (read && ch.isOpen()) {
// Something is ready to read, so consume it now // Something is ready to read, so consume it now
unsafe.epollInReady(); unsafe.epollInReady();
} }
if (close) {
unsafe.epollRdHupReady();
}
} else { } else {
// We received an event for an fd which we not use anymore. Remove it from the epoll_event set. // We received an event for an fd which we not use anymore. Remove it from the epoll_event set.
Native.epollCtlDel(epollFd, fd); Native.epollCtlDel(epollFd, fd);