New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#2426] Not cause busy loop when interrupt Thread of AbstractNioSelector #2868
Conversation
@trustin please review... I would love to have this in all 3.6+ branches and 3.2 and cut a 3.6 and 3.2 release with it for Red Hat to consume . |
Thanks norman for your help, this saved us time. |
// See https://github.com/netty/netty/issues/2426 | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Selector.select() returned prematurely because " + | ||
"Thread.currentThread().interrupt() was called. Use " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
' .. because the I/O thread has been interrupted. Use shutdown() to shut the NioSelector down.'
I proposed to rephrase the messages and comments. Besides that, it looks fine to me. |
Once done, please feel free to merge. |
@trustin I will need to backport this to 3.6 and 3.2 also and cut a release. What else branches I should backport ? |
Motivation: Because Thread.currentThread().interrupt() will unblock Selector.select() we need to take special care when check if we need to rebuild the Selector. If the unblock was caused by the interrupt() we will clear it and move on as this is most likely a bug in a custom ChannelHandler or a library the user makes use of. Modification: Clear the interrupt state of the Thread if the Selector was unblock because of an interrupt and the returned keys was 0. Result: No more busy loop caused by Thread.currentThread().interrupt()
452e5ed
to
0a374cd
Compare
3.9? :-) |
@trustin ok 3.9 , 3.6 and .3.2 (sigh). Will cut a release for 3.6 and 3.2 ... Should I also do for 3.9 ? |
@trustin was wrong... only need 3.6 (not 3.2 :)) |
No need to release. I just meant this commit should go to the latest stable branches including 3.9. and what about 4.x and master? Are we affected there, either? |
No it is fixed already in master and 4.0
|
Was merged into 3.6 and 3.9 branches. |
Today I debug teiid code(it use netty 3.6.2) find a easy way to reproduce high cpu in 3.6.2, if we run the following code:
These code cause 2 threads(netty boss threads and netty worker threads) high cpu(100% cpu retained). I also verified fixed version 3.6.10.Final(https://github.com/netty/netty/releases/tag/netty-3.6.10.Final), it fixed the issue. I hope my founding can help others, http://ksoong.org/netty-highcpu/ have more details. |
Due to netty/netty#2868 we need at least 3.6.…
to netty 3.10.6.Final
Motivation:
Because Thread.currentThread().interrupt() will unblock Selector.select() we need to take special care when check if we need to rebuild the Selector. If the unblock was caused by the interrupt() we will clear it and move on as this is most likely a bug in a custom ChannelHandler or a library the user makes use of.
Modification:
Clear the interrupt state of the Thread if the Selector was unblock because of an interrupt and the returned keys was 0.
Result:
No more busy loop caused by Thread.currentThread().interrupt()