Jetty
  1. Jetty
  2. JETTY-1379

java.nio.channels.CancelledKeyException in Jetty client

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 6.1.25
    • Fix Version/s: None
    • Component/s: Client
    • Labels:
      None
    • Environment:
      Linux x86_64 GNU/Linux 2.6.18-194.el5
      java: 1.6.0_21; vm version: 17.0-b16 (Java HotSpot(TM) 64-Bit Server VM); vendor: Sun Microsystems Inc.; vm vendor: Sun Microsystems Inc.
    • Number of attachments :
      0

      Description

      We run a system where we have an embedded Jetty client doing a lot of small HTTP requests to an HTTP server. During a stress test, the following error occurred:

      java.nio.channels.CancelledKeyException
      at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)
      at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:59)
      at org.mortbay.io.nio.SelectChannelEndPoint.updateKey(SelectChannelEndPoint.java:325)
      at org.mortbay.io.nio.SelectChannelEndPoint.scheduleWrite(SelectChannelEndPoint.java:309)
      at org.mortbay.jetty.client.HttpConnection.send(HttpConnection.java:131)
      at org.mortbay.jetty.client.HttpDestination.doSend(HttpDestination.java:503)
      at org.mortbay.jetty.client.HttpDestination.send(HttpDestination.java:459)
      at org.mortbay.jetty.client.HttpClient.send(HttpClient.java:143)
      ...

      Looking at the code in 6.1.25:

      if (getChannel().isOpen())

      { => ops = ((_key!=null && _key.isValid())?_key.interestOps():-1); _interestOps = ((!_dispatched || _readBlocked) ? SelectionKey.OP_READ : 0) | ((!_writable || _writeBlocked) ? SelectionKey.OP_WRITE : 0); }

      there is a race condition where the key can be cancelled between the _key.isValid() check and calling _key.interestOps() which is likely to cause this exception. Looking at the Jetty-7 code:

      try

      { ops = ((_key!=null && _key.isValid())?_key.interestOps():-1); }

      catch(Exception e)

      { _key=null; Log.ignore(e); }

      This catches a possible exception and sets the key to null. I suspect this code will fix the intermittent java.nio.channels.CancelledKeyException that we are seeing. Can this code be backported to Jetty-6?

        Activity

        Hide
        Jan Bartel added a comment -

        Please check if it is ok to backport this fix to jetty-6.

        Show
        Jan Bartel added a comment - Please check if it is ok to backport this fix to jetty-6.
        Jan Bartel made changes -
        Field Original Value New Value
        Assignee Greg Wilkins [ gregw ]
        Jan Bartel made changes -
        Assignee Greg Wilkins [ gregw ] Jan Bartel [ janb ]
        Hide
        Jan Bartel added a comment -

        jetty-6 is mainly only having security patches applied to it, and releases are really prompted by security fixes. So realistically, I don't see us porting this to jetty-6. If this is commercially important to you, then I suggest perhaps you talk to http://www.webtide.com about support for an old version.

        regards
        Jan

        Show
        Jan Bartel added a comment - jetty-6 is mainly only having security patches applied to it, and releases are really prompted by security fixes. So realistically, I don't see us porting this to jetty-6. If this is commercially important to you, then I suggest perhaps you talk to http://www.webtide.com about support for an old version. regards Jan
        Jan Bartel made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Jan Bartel
            Reporter:
            Michiel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: