Uploaded image for project: 'Geronimo'
  1. Geronimo
  2. GERONIMO-288

NIO Network code might send unordered messages

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • None
    • None
    • core
    • None

    Description

      Hi,
      Geronimo network code might deliver messages out of order.

      To be more specific, the network code tries to write a buffer and if remaining()>0, registers an OP_WRITE interest in order to drain the buffer contents later (when the channel is available for write). When the server is loaded, things can get hairy and we might receive another write event which might get scheduled to run before the OP_WRITE is processed.

      More specifically, SocketProtocol.serviceWrite reads:

      long count = socketChannel.write(sendBuffer);
      log.trace("Wrote " + count);
      if (sendBuffer[i].hasRemaining())

      { // not all was delivered in this call setup selector // so we setup to finish sending async. log.trace("+OP_WRITE " + selectionKey); selectorManager.addInterestOps(selectionKey, SelectionKey.OP_WRITE); return; }

      Since there's no synchronization, in a situation where the selector returns with OP_WRITE (in SelectorManager) but not yet finds the chance to process the event, another thread loaded with a read event might sneak in and call the above lines, the result of which would be sending data out of order.

      Regards,
      Bulent Erdemir

      Attachments

        Activity

          People

            maguro Alan Cabrera
            bulente Bulent Erdemir
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: