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

Race condition causes CancelledKeyException in TAsyncClientManager

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 0.4
    • Java - Library
    • None
    • Patch Available

    Description

      Currently, TAsyncClientMethod cancels its selection key on a successful method call. The current model assumes the key goes away and the client gets a new key on the next Selector registration, which is incorrect - the cancelled key can hang around, with the implication that the developer needs to check key.isValid() on the next selector action, which TAsyncClientMethod currently does. However, if the developer re-uses the client for another call, you can get a CancelledKeyException from the Selector#register call, which crashes the SelectorThread. This occurs once you have sufficient concurrency on the Selector - cancelled key cleanup takes longer, so we hit this condition.

      Attached is a patch with fix and regression test. Summary of fix:

      1) Don't cancel() the key after a successful method call.
      2) Catch CancelledKeyException in the SelectorThread, so the manager can't die.
      3) Add an onError method to TAsyncMethodCall, so that the SelectorThread can notify the client of an error on selector registration.

      Attachments

        1. async_client_catch_all.diff
          8 kB
          Ning Liang
        2. async_thrift_catch_except.diff
          7 kB
          Ning Liang
        3. async_thrift.diff
          6 kB
          Ning Liang

        Activity

          People

            bryanduxbury Bryan Duxbury
            ning Ning Liang
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: