Skip to content

spring jms shutdown frizzing application context #33432

@stri4e

Description

@stri4e

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comin: messagingIssues in messaging modules (jms, messaging)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions