private void rebuildSelector() {
        selectorRebuildCount.inc();
        Selector newSelector = newSelector(logger);
        Selector oldSelector = this.selector;

        // reset each pipeline's selectionKey, cancel the old keys
        for (SelectionKey key : oldSelector.keys()) {
            NioPipeline pipeline = (NioPipeline) key.attachment();
            SelectableChannel channel = key.channel();
            try {
                int ops = key.interestOps();
                SelectionKey newSelectionKey = channel.register(newSelector, ops, pipeline);
                pipeline.setSelectionKey(newSelectionKey);
            } catch (ClosedChannelException e) {
                logger.info("Channel was closed while trying to register with new selector.");
            } catch (CancelledKeyException e) {
                // a CancelledKeyException may be thrown in key.interestOps
                // in this case, since the key is already cancelled, just do nothing
                ignore(e);
            }
            key.cancel();
        }

        // close the old selector and substitute with new one
        closeSelector();
        this.selector = newSelector;
        logger.warning("Recreated Selector because of possible java/network stack bug.");
    }
private void rebuildSelector ( ) { selectorRebuildCount . inc ( ) ; Selector newSelector = newSelector ( logger ) ; Selector oldSelector = this . selector ; for ( SelectionKey key : oldSelector . keys ( ) ) { NioPipeline pipeline = ( NioPipeline ) key . attachment ( ) ; SelectableChannel channel = key . channel ( ) ; try { int ops = key . interestOps ( ) ; SelectionKey newSelectionKey = channel . register ( newSelector , ops , pipeline ) ; pipeline . setSelectionKey ( newSelectionKey ) ; } catch ( ClosedChannelException e ) { logger . info ( "Channel was closed while trying to register with new selector." ) ; } catch ( CancelledKeyException e ) { ignore ( e ) ; } key . cancel ( ) ; } closeSelector ( ) ; this . selector = newSelector ; logger . warning ( "Recreated Selector because of possible java/network stack bug." ) ; }
after we have blocked for selector.select in #runSelectLoopWithSelectorFix