Skip to content

Conversation

@alex-berger
Copy link

The submission of a task after checking isShutdown on the EventLoop might fail as the EventLoop might be shutdown between the call to isShutdown and execute.

Anyhow, the whole thing feels a little bit warm and fuzzy to me. Is it really the right thing to do, to execute channel bound I/O events on the underlying AsynchronousChannelGroup's thread when the
channel's EventLoop is shutdown? The JDK API documentation for AsynchronousChannelGroup#withThreadPool clearly advises against such usage (see http://docs.oracle.com/javase/7/docs/api/java/nio/channels/AsynchronousChannelGroup.html#withThreadPool(java.util.concurrent.ExecutorService))

Should this really happen (Channel is still alive but its EventLoop is shutdown), wouldn't it be better to just close the Channel.

ab and others added 6 commits October 17, 2012 09:09
shutdown. Is this really the right thing to do? If an EventLoop is
shutdown shouldn't we just close all it associated channels instead of
executing their I/O events by calling command.run()?

The JDK documentation for AsynchronousChannelGroup.withThreadPool says:

"Care should be taken when configuring the executor service. It should
support direct handoff or unbounded queuing of submitted tasks, and the
thread that invokes the execute method should never invoke the task
directly. An implementation may mandate additional constraints."
@normanmaurer
Copy link
Member

I think you are right.. directly running the "Task" in the calling Thread is not good. I think if it was really shutdown we should throw an RejectedExecutionException. So I think it would be better if we check with "isShutdown()" if true we will throw the RejectedExecutionException. If not we try to execute the Tasks. This may also lead to the RejectedExecutionException but this is ok.

WDYT ?

@alex-berger
Copy link
Author

If you want to go that way, you do not need the isShutdown check at all. Just call l.execute.

But in case the EventLoop is shutdown and a RejectedExecutionException is thrown, who is supposed to receive that Exception? The calling Thread is an underlying "hidden" Thread from the AsynchronousChannelGroup.

trustin added a commit that referenced this pull request Oct 23, 2012
- Ensure the event loop threads are never terminated before all tasks
  submitted by JDK are executed
- Close all open connections before terminating an event loop
@trustin
Copy link
Member

trustin commented Oct 23, 2012

c38c1d0 should fix the race condition completely, but at the moment I can't test it thoroughly because of MacOS X JDK issues. @alex-berger, would you mind if I ask you to test my commit and let me know it fixes your problem?

trustin added a commit that referenced this pull request Oct 23, 2012
- Fix a bug where shutdown() blocks indefinitely sometimes
@alex-berger
Copy link
Author

Hi Trustin
I have no test case for this problem. I just saw this problem when reviewing the code (while trying to understand the new threading model of Netty 4). However, I will review the changes you made and comment on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants