Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5230

Fix connection leak and CancelledKeyException when handling Epoll bug

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.13.0
    • 0.21.0
    • Java - Library
    • None
    • java version "1.8.0_161"

    Description

      1. When Epoll bug occurs, the TThreadedSelectorServer.rebuildSelector rebuilds only the channel has events, the idle connection was ignored and caused connection leak

       

      for (SelectionKey key : oldSelector.selectedKeys()) {
        if (!key.isValid() && key.readyOps() == 0)
          continue;
        SelectableChannel channel = key.channel();
        Object attachment = key.attachment();
      
        try {
          if (attachment == null) {
            channel.register(newSelector, key.readyOps());
          } else {
            channel.register(newSelector, key.readyOps(), attachment);
          }
        } catch (ClosedChannelException e) {
          LOGGER.error("Register new selector key error.", e);
        }
      }
      
      selector = newSelector;
      try {
        oldSelector.close();
      } catch (IOException e) {
        LOGGER.error("Close old selector error.", e);
      }
      
      

      2. When re-register the channel to new selector, the interested ops should same as before, not only the readyOps

       

      3. In the same code block, the channel will be registered to a new selector and the previous selector will be closed, but the FrameBuffer is still holding the previous selector causing the FrameBuffer in a wrong state. When the FrameBuffer is trying to processing the channel, it may occur a CancelledKeyException.This issue (CancelledKeyException) has been reported before:https://issues.apache.org/jira/browse/THRIFT-4847

      Attachments

        1. screenshot-3.png
          338 kB
          Xinyu Tan
        2. screenshot-2.png
          580 kB
          Xinyu Tan
        3. screenshot-1.png
          580 kB
          Xinyu Tan

        Issue Links

          Activity

            People

              jensg Jens Geyer
              zengji zengji
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m