Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JmsUtils.commitIfNecessary catches and ignores JMS IllegalStateException, losing message with ActiveMQ Artemis #32473

Closed
luigidemasi opened this issue Mar 18, 2024 · 0 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@luigidemasi
Copy link

JmsUtils.commitIfNecessary catch and ignore jakarta.jms.IllegalStateException saying it can only happens in case of JTA transaction:

	public static void commitIfNecessary(Session session) throws JMSException {
		Assert.notNull(session, "Session must not be null");
		try {
			session.commit();
		}
		catch (jakarta.jms.TransactionInProgressException | jakarta.jms.IllegalStateException ex) {
			// Ignore -> can only happen in case of a JTA transaction.
		}
	}

but there are cases where it can be raised also in local transaction, for example if a broker restart happens between send and commit:

13:16:57.143 [Thread-1] INFO org.springframework.jms.connection.CachingConnectionFactory -- Encountered a JMSException - resetting the underlying JMS Connection
jakarta.jms.JMSException: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ219006: Channel disconnected]
	at org.apache.activemq.artemis.jms.client.ActiveMQConnection$JMSFailureListener.connectionFailed(ActiveMQConnection.java:714)
	at org.apache.activemq.artemis.jms.client.ActiveMQConnection$JMSFailureListener.connectionFailed(ActiveMQConnection.java:735)
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.callSessionFailureListeners(ClientSessionFactoryImpl.java:868)
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.failoverOrReconnect(ClientSessionFactoryImpl.java:794)
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.handleConnectionFailure(ClientSessionFactoryImpl.java:566)
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.handleConnectionFailure(ClientSessionFactoryImpl.java:559)
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl$1.run(ClientSessionFactoryImpl.java:417)
	at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:57)
	at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:32)
	at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:68)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118)
Caused by: org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException: AMQ219006: Channel disconnected
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.connectionDestroyed(ClientSessionFactoryImpl.java:410)
	at org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector$Listener$1.run(NettyConnector.java:1240)
	... 6 common frames omitted

I created a couple of tests that reproduce the issue simulating the broker restart between send and commit:

https://github.com/luigidemasi/spring-jms-commit-issue

@luigidemasi luigidemasi changed the title spring-jms: JmsUtils.commitIfNecessary ignore jakarta.jms.IllegalStateException and this leads to message lost even if session is transacted spring-jms: JmsUtils.commitIfNecessary catch and ignore jakarta.jms.IllegalStateException and this leads to message lost even if session is transacted Mar 18, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 18, 2024
@jhoeller jhoeller self-assigned this Mar 18, 2024
@jhoeller jhoeller added in: messaging Issues in messaging modules (jms, messaging) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 18, 2024
@jhoeller jhoeller added this to the 6.1.6 milestone Mar 18, 2024
@jhoeller jhoeller changed the title spring-jms: JmsUtils.commitIfNecessary catch and ignore jakarta.jms.IllegalStateException and this leads to message lost even if session is transacted JmsUtils.commitIfNecessary catches and ignores JMS IllegalStateException, losing message with ActiveMQ Artemis Mar 18, 2024
@jhoeller jhoeller added the for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x label Mar 18, 2024
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x labels Mar 18, 2024
@jhoeller jhoeller added the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Mar 18, 2024
@github-actions github-actions bot removed the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Mar 18, 2024
jhoeller added a commit that referenced this issue Mar 18, 2024
jhoeller added a commit that referenced this issue Mar 18, 2024
Yangushan pushed a commit to Yangushan/spring-framework that referenced this issue Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants