Skip to content

100% CPU (core) on NioClientSocketPipelineSink#Boss #535

Closed

Description

@kimchy

Managed to get into this state twice while running my test suite, second time managed to put a breakpoint and debug it a bit. Sadly, haven't managed to repro it since (working on it).

Some details, seems like the select(10) always returns immediately, returning 0, but there is a single key in the selector. keys. Sadly, did not check the shutdown flag or the executor service isShutdown flag, but I suspect the executor service would have been shut down, as this is part of a test suite that starts and stops all the time, and somehow it got into this state while it should have "exited".

I know, not much info, but was thinking that I would open this just in case. Still trying to repro this for the past few days, no luck yet.

Activity

  1. kimchy commented on Aug 22, 2012

    @kimchy
    Author

    more info:

    • int selectedKeyCount = selector.select(10) returns immediatly with 0.
    • selector.keys() is not empty with 1 key, the details for the key at: channel (SockeyChannel[closed]), index 0, interestedOps 8, readyOps 0, valid true.
    • The ((ExecutorService) bossExecutor).isShutdown() is true (i.e. it was properly shutdown)

    It seems like its getting into a spin in this case, where it always keeps on retrying. This might happen because of an Unexpected exception in the selector loop happening with a CancelledKeyException (still trying to track this one down), sadly don't have the stack trace for it.

    Note, I don't believe that this happens only on close of the boss, as I have seen users reporting the CancelledKeyException even when no bootstrap is actually being closed.

    Here is the CancelledKeyException stack trace (note, netty is embedded):

    12:24:58,006  WARN New I/O client boss #11 NioClientSocketPipelineSink:internalWarn:105 - Unexpected exception in the selector loop.
    java.nio.channels.CancelledKeyException
        at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:73)
        at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:87)
        at java.nio.channels.SelectionKey.isConnectable(SelectionKey.java:336)
        at org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:353)
        at org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:276)
        at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
        at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
    

    @normanmaurer / @trustin, what do you think?

  2. kimchy commented on Aug 22, 2012

    @kimchy
    Author

    One more note on the java.nio.channels.CancelledKeyException, it happens when the bootstrap is not closed as well.

  3. normanmaurer commented on Aug 23, 2012

    @normanmaurer
    Member

    @kimchy could you please checkout the nio_100percent_cpu_fix branch, build a snapshot and test with it ? I think this should fix it

  4. kimchy commented on Aug 23, 2012

    @kimchy
    Author

    @normanmaurer will do today, it took me a couple of days to get to when it happens..., so hard to say when it stops happening, but, looking at your fix, it looks good!

  5. normanmaurer commented on Aug 23, 2012

    @normanmaurer
    Member

    @kimchy just did some minor cleanup/change to make it "more compact". So please use this one... I'm awaiting your feedback! And thanks again for reporting!

  6. kimchy commented on Aug 23, 2012

    @kimchy
    Author

    @normanmaurer the fix is great, I suggest we push it, its important. I did though get into the same test once (sadly) with 100% CPU as described in the initial issue description, not much more info yet. I am still trying to figure out if its related to trying to release the bootstrap with concurrency problems around trying to open a connection at the same time, or its not really related to releasing a bootstrap, and its simply in a shutdown state because the test released it. Maybe @trustin can chip in...

  7. kimchy commented on Aug 23, 2012

    @kimchy
    Author

    @normanmaurer I am going to play a bit in my usecase, and make sure that no client connection might be initiated while shutting down the client bootstrap, will see if it helps, but +1 on pushing your fix for now.

  8. normanmaurer commented on Aug 24, 2012

    @normanmaurer
    Member

    So you thing the commit fix only part of the problem, right?

    Sent from my iPhone. Excuse any typos....

    Am 24.08.2012 um 01:21 schrieb Shay Banon [email protected]:

    @normanmaurer the fix is great, I suggest we push it, its important. I did though get into the same test once (sadly) with 100% CPU as described in the initial issue description, not much more info yet. I am still trying to figure out if its related to trying to release the bootstrap with concurrency problems around trying to open a connection at the same time, or its not really related to releasing a bootstrap, and its simply in a shutdown state because the test released it. Maybe @trustin can chip in...

    —
    Reply to this email directly or view it on GitHub.

  9. kimchy commented on Aug 24, 2012

    @kimchy
    Author

    @normanmaurer yes, I don't think its a full fix...

  10. normanmaurer commented on Aug 24, 2012

    @normanmaurer
    Member

    A stacktrace and a thread-dump could help me to solve it completly. Or even
    better a yourkit dump ;)

    2012/8/24 Shay Banon [email protected]

    @normanmaurer https://github.com/normanmaurer yes, I don't think its a
    full fix...

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/535#issuecomment-7993295.

  11. kimchy commented on Aug 24, 2012

    @kimchy
    Author

    Not sure if that will help, what happens is that you get into a spin in the client Boos thread with all the mentioned state explained in the issue dec (current keys, and so on). A thread dump will just show that its in the middle of doing something in the client boss thread.

  12. added a commit that references this issue on Aug 24, 2012
  13. 1 remaining item

  14. normanmaurer commented on Aug 24, 2012

    @normanmaurer
    Member

    @kimchy could you please tell me what java version you are using and what os ? I have a suspect, and if I'm right then its a jdk bug !

  15. normanmaurer commented on Aug 24, 2012

    @normanmaurer
    Member

    @kimchy please test with latest code out of the jdk_bug_workaround branch. I think that should be it.

    https://github.com/netty/netty/tree/jdk_bug_workaround

    :)

  16. kimchy commented on Aug 24, 2012

    @kimchy
    Author

    @normanmaurer I was suspecting that, but I never managed to prove that this was the problem, since once I managed to recreate it, the select returns 0, but the seclectKeys was empty, though, I suspect, the weird combination of select return 0 yet having selectedKeys might be applied only for the first iteration and then we get into the constant state described above.

  17. normanmaurer commented on Aug 24, 2012

    @normanmaurer
    Member

    I was able to at least see this one time.. So I think this should fix it. Let me know if you still manage to get into 100%cpu usage.

    Sent from my iPhone. Excuse any typos....

    Am 24.08.2012 um 19:08 schrieb Shay Banon [email protected]:

    @normanmaurer I was suspecting that, but I never managed to prove that this was the problem, since once I managed to recreate it, the select returns 0, but the seclectKeys was empty, though, I suspect, the weird combination of select return 0 yet having selectedKeys might be applied only for the first iteration and then we get into the constant state described above.

    —
    Reply to this email directly or view it on GitHub.

  18. kimchy commented on Aug 24, 2012

    @kimchy
    Author

    Great that you were able to repro it!, it takes me some time to get to a state where it happens. Wondering, with the change you made, if it shouldn't be applied to other places where the return value of the select method is used, and process the selectedKeys regardless of the return value.

  19. normanmaurer commented on Aug 25, 2012

    @normanmaurer
    Member

    Yeah will check.. Just wanted to see first if it fix it for you.

    Sent from my iPhone. Excuse any typos....

    Am 24.08.2012 um 22:11 schrieb Shay Banon [email protected]:

    Great that you were able to repro it!, it takes me some time to get to a state where it happens. Wondering, with the change you made, if it shouldn't be applied to other places where the return value of the select method is used, and process the selectedKeys regardless of the return value.

    —
    Reply to this email directly or view it on GitHub.

  20. normanmaurer commented on Aug 25, 2012

    @normanmaurer
    Member

    @kimchy @trustin I think this 100% cpu usage could also be created because of an epoll(..) bug.

    See #565

  21. normanmaurer commented on Aug 29, 2012

    @normanmaurer
    Member

    Merged in the workaround for epoll bug. @kimchy could you please retest with latest code out of the 3 branch and see if you can still get into 100% cpu usage ?

  22. added a commit that references this issue on Aug 29, 2012
  23. normanmaurer commented on Aug 30, 2012

    @normanmaurer
    Member

    Fixed.. Thanks for review again

    2012/8/29 Shay Banon [email protected]

    Quick look at current 3 brach, this:
    https://github.com/netty/netty/blob/3/src/main/java/org/jboss/netty/channel/socket/nio/SelectorUtil.java#L61,
    should be toNanos, not toMicros.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/535#issuecomment-8137935.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions