Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-5228

Race condition maintaining acknowledgements when pushing messages to the client

    XMLWordPrintable

    Details

      Description

      There is a race condition when maintaining/checking message acknowledgements
      for a subscription when messages are pushed to the client.

      i.e. when the client asks for a message and there are none, the client is registered
      as wanting a message and when a message arrives, the message is sent to the client.

      This involves maintaining a "list" of unacknowledged messages for that client/subscription
      which must be checked before we allow removal of the the subscription during close.

      However, for pushing the maintenance of the unacknowledged messages can
      race with the close of the subscription because they are not maintained in the same synchronized block
      as deciding the client wants the message.

      BasicQueue::internalAddMessage()

      try
      {
      Subscription found = null;

      // In this synchronized block we decide that a client wants the message
      synchronized (receivers)
      {
      if (receivers.size() != 0)
      {
      for (Iterator it = receivers.iterator(); it.hasNext()
      {
      Subscription sub = (Subscription) it.next();
      if (sub.accepts(message.getHeaders()))

      { it.remove(); found = sub; break; }

      }
      }

      ...

      But only later outside this block do we maintain the unacknowledged messages

      // Queue to the receiver
      if (found != null)
      queueMessageForSending(found, message);

      This means that during the ... above a close of the subscription which leads to an invocation
      of hasUnackedMessages() could decide there are no unacknoweldged messages.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  adrian.brock Adrian Brock
                  Reporter:
                  adrian.brock Adrian Brock
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: