spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

spring jms shutdown frizzing application context

Open stri4e opened this issue 1 year ago • 0 comments

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.

stri4e avatar Aug 26 '24 17:08 stri4e