Qpid
  1. Qpid
  2. QPID-3879

Session#close() on session can produce spurious "dispatcher is not started" messages at ERROR to client logs

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.10, 0.12, 0.14, 0.16
    • Fix Version/s: 0.17
    • Component/s: Java Client
    • Labels:
      None

      Description

      Calling Session#close() on a session which is still in the process of receiving messages can result in the following error message to the client log:

      Dispatcher-Channel-1 2012-01-25 22:44:25,298 ERROR [apache.qpid.thread.LoggingUncaughtExceptionHandler] Uncaught exception in thread "Dispatcher-Channel-1"
      java.lang.IllegalStateException: dispatcher is not started
              at org.apache.qpid.client.AMQSession.dispatch(AMQSession.java:3192)
              at org.apache.qpid.client.message.UnprocessedMessage.dispatch(UnprocessedMessage.java:55)
              at org.apache.qpid.client.AMQSession$Dispatcher.run(AMQSession.java:3349)
              at java.lang.Thread.run(Thread.java:680)
      

      The problem is longstanding issue, but has probably become more noticeable since QPID-1670 which introduced a uncaught exception handle that directs such errors to SLF4J (rather than stderr). Our tests in general don't show the issue because they tend to consume all the tests message.

        Activity

        Hide
        Keith Wall added a comment -

        There is a race between the Dispatcher thread and the thread calling Session#close() (which resets to the reference to the dispatcher within #closeConsumers()).

        AMQSession$Dispatcher.java
        while (!_closed.get() && ((disp = (Dispatchable) _queue.take()) != null))
        {
            disp.dispatch(AMQSession.this);
        }
        

        In the above, the LHS of the while expression checks the Dispatcher is not closed, then the RHS blocks until a message arrive. This allows the possibility that that the Dispatcher#close() could have been called (and its reference nulled) by the time the take() returns. In the unlucky case, a message is added to the dispatch queue and AMQSession#close() occurs, causing the IllegalStateException further down the delivery path.

        The impact on the end-user application is minimal. As the session is being closed, the Broker will ensure that any unack'd messages will be redelivered. However, the error message will cause confusion to our users.

        Show
        Keith Wall added a comment - There is a race between the Dispatcher thread and the thread calling Session#close() (which resets to the reference to the dispatcher within #closeConsumers()). AMQSession$Dispatcher.java while (!_closed.get() && ((disp = (Dispatchable) _queue.take()) != null )) { disp.dispatch(AMQSession. this ); } In the above, the LHS of the while expression checks the Dispatcher is not closed, then the RHS blocks until a message arrive. This allows the possibility that that the Dispatcher#close() could have been called (and its reference nulled) by the time the take() returns. In the unlucky case, a message is added to the dispatch queue and AMQSession#close() occurs, causing the IllegalStateException further down the delivery path. The impact on the end-user application is minimal. As the session is being closed, the Broker will ensure that any unack'd messages will be redelivered. However, the error message will cause confusion to our users.
        Hide
        Keith Wall added a comment -

        Commit applied. Robbie, would you mind reviewing please?

        Show
        Keith Wall added a comment - Commit applied. Robbie, would you mind reviewing please?
        Hide
        Robbie Gemmell added a comment -

        Looks ok to me.

        Show
        Robbie Gemmell added a comment - Looks ok to me.

          People

          • Assignee:
            Robbie Gemmell
            Reporter:
            Keith Wall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development