Author: elecharny Date: Wed Jan 27 22:59:51 2010 New Revision: 903897 URL: http://svn.apache.org/viewvc?rev=903897&view=rev Log: Fixed the fix for spinning epoll : the session wasn't re-attached with the selectedKey when switching the selector
Modified: mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java Modified: mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java?rev=903897&r1=903896&r2=903897&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java Wed Jan 27 22:59:51 2010 @@ -1065,47 +1065,31 @@ long delta = (t1 - t0); synchronized (wakeupCalled) { - - if (selected == 0) { - if (!wakeupCalled.get()) { - if (delta < 100) { - // Last chance : the select() may have been - // interrupted - // because we have had an closed channel. - if (isBrokenConnection()) { - // we can reselect immediately - continue; - } else { - LOG.warn("Create a new selector. Selected is 0, delta = " - + (t1 - t0)); - // Ok, we are hit by the nasty epoll - // spinning. - // Basically, there is a race condition - // which cause - // a closing file descriptor not to be - // considered as - // available as a selected channel, but - // it stopped - // the select. The next time we will - // call select(), - // it will exit immediately for the same - // reason, - // and do so forever, consuming 100% - // CPU. - // We have to destroy the selector, and - // register all - // the socket on a new one. - registerNewSelector(); - } - - // and continue the loop - continue; - } + if ((selected == 0) && !wakeupCalled.get() && (delta < 100)) { + // Last chance : the select() may have been + // interrupted because we have had an closed channel. + if (isBrokenConnection()) { + // we can reselect immediately + continue; } else { - // System.out.println("Waited one second"); + LOG.warn("Create a new selector. Selected is 0, delta = " + + (t1 - t0)); + // Ok, we are hit by the nasty epoll + // spinning. + // Basically, there is a race condition + // which causes a closing file descriptor not to be + // considered as available as a selected channel, but + // it stopped the select. The next time we will + // call select(), it will exit immediately for the same + // reason, and do so forever, consuming 100% + // CPU. + // We have to destroy the selector, and + // register all the socket on a new one. + registerNewSelector(); } - } else { - // System.out.println("Nb selected : " + selected); + + // and continue the loop + continue; } wakeupCalled.getAndSet(false); @@ -1113,6 +1097,7 @@ // Manage newly created session first nSessions += handleNewSessions(); + updateTrafficMask(); // Now, if we have had some incoming or outgoing events, Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java?rev=903897&r1=903896&r2=903897&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java Wed Jan 27 22:59:51 2010 @@ -131,11 +131,17 @@ // Open a new selector Selector newSelector = Selector.open(); + // Loop on all the registered keys, and register them on the new selector for (SelectionKey key : keys) { SelectableChannel ch = key.channel(); - ch.register(newSelector, key.interestOps()); + + // Don't forget to attache the session, and back ! + NioSession session = (NioSession)key.attachment(); + SelectionKey newKey = ch.register(newSelector, key.interestOps(), session); + session.setSelectionKey( newKey ); } + // Now we can close the old selector and switch it selector.close(); selector = newSelector; }