Hi, all

Faced with issue related to all version of spring-jms. When spring-jms configuration with BackOf and app try to close application context after retry (jms do retry to established connection and connection establish only 1 sec, after that do retry again), and after 20 counts, faced with problem when AppContext frozen and app don't shutdown. I try to investigate why and found next code:

@Override
    protected void doShutdown() throws JMSException {
        logger.debug("Waiting for shutdown of message listener invokers");
        this.lifecycleLock.lock();
        try {
            long receiveTimeout = getReceiveTimeout();
            long waitStartTime = System.currentTimeMillis();
            int waitCount = 0;
            while (this.activeInvokerCount > 0) {
                if (waitCount > 0 && !isAcceptMessagesWhileStopping() &&
                        System.currentTimeMillis() - waitStartTime >= receiveTimeout) {
                    // Unexpectedly some invokers are still active after the receive timeout period
                    // -> interrupt remaining receive attempts since we'd reject the messages anyway
                    for (AsyncMessageListenerInvoker scheduledInvoker : this.scheduledInvokers) {
                        scheduledInvoker.interruptIfNecessary();
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Still waiting for shutdown of " + this.activeInvokerCount +
                            " message listener invokers (iteration " + waitCount + ")");
                }
                // Wait for AsyncMessageListenerInvokers to deactivate themselves...
                if (receiveTimeout > 0) {
                    this.lifecycleCondition.await(receiveTimeout, TimeUnit.MILLISECONDS);
                }
                else {
                    this.lifecycleCondition.await();
                }
                waitCount++;
            }
            // Clear remaining scheduled invokers, possibly left over as paused tasks
            for (AsyncMessageListenerInvoker scheduledInvoker : this.scheduledInvokers) {
                scheduledInvoker.clearResources();
            }
            this.scheduledInvokers.clear();
        }
        catch (InterruptedException ex) {
            // Re-interrupt current thread, to allow other threads to react.
            Thread.currentThread().interrupt();
        }
        finally {
            this.lifecycleLock.unlock();
        }
    }

And after all retries app faced with issue when connection not working but this field this.activeInvokerCount has 1 count. And application try to do shutdown but can't. Also thread inside AsyncMessageListenerInvoker is null, so this code

for (AsyncMessageListenerInvoker scheduledInvoker : this.scheduledInvokers) {
    scheduledInvoker.interruptIfNecessary();
}

not interrupt.

Thanks.

Comment From: bclozel

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.