You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Gary Tully (JIRA)" <ji...@apache.org> on 2018/06/13 10:42:00 UTC
[jira] [Reopened] (AMQ-2659) JMSException incorrectly thrown when
using XAConnection/XASession outside a transaction
[ https://issues.apache.org/jira/browse/AMQ-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Tully reopened AMQ-2659:
-----------------------------
Revisiting this, I now think the change needs to be configurable.
I came across a use case with an XASession and consumer.receive(timeout) where the XA transaction rolls back before the timeout and where the subsequent received message gets auto acked in error, effectively loosing a message. Before this change, the doStartTransaction would throw and the receive would fail.
Because the lifecycle of the transaction is independent of the consumer and session, having the session work without a transaction will leave the potential for holes in transacted work. It should not be enabled by default.
In addition, XASession.getTransacted() should always return true as per the [javadoc|https://docs.oracle.com/javaee/5/api/javax/jms/XASession.html#getTransacted()], not sure why that was missed 6years ago.
I will rework the changes to allow the use of an xasession outside of a transaction once there is an explicit request to use a non transacted ack mode via setXaAckMode.
By default, work outside an xa transaction will throw an error as it should.
> JMSException incorrectly thrown when using XAConnection/XASession outside a transaction
> ---------------------------------------------------------------------------------------
>
> Key: AMQ-2659
> URL: https://issues.apache.org/jira/browse/AMQ-2659
> Project: ActiveMQ
> Issue Type: Bug
> Components: Broker
> Affects Versions: 5.3.0
> Reporter: Eugene Rodos
> Assignee: Gary Tully
> Priority: Major
> Fix For: 5.4.0
>
> Attachments: JMSConsumerTestXA.java, JmsTestSupportXA.java
>
>
> Currently, if one attempts to use an XAConnection (implemented by ActiveMQXAConnection) and consequently an XASession (implemented by ActiveMQXASession) outside a transaction, a JMSException is thrown. However, nowhere in the JMS Spec does it say that if an XAConnection/XASession is used, it _*must*_ be enlisted in a transaction. It is perfectly legal to _*not*_ start a transaction but still use the XA objects.
> I propose that the following 2 methods in ActiveMQXASession be changed as follows to resolve this bug:
> {noformat}
> public boolean getTransacted() throws JMSException {
> return getTransactionContext().isInXATransaction();
> }
> /**
> * This is called before transacted work is done by the session.
> * XA transactions are controlled outside of the session so
> * nothing has to be done here. The only reason for this method
> * to be here is to override the parent.
> */
> protected void doStartTransaction() {
> }
> {noformat}
> \\
> The current version of these methods is as follows (for reference):
> {noformat}
> public boolean getTransacted() throws JMSException {
> return true;
> }
> /**
> * This is called before transacted work is done by
> * the session. XA Work can only be done when this
> * XA resource is associated with an Xid.
> *
> * @throws JMSException not associated with an Xid
> */
> protected void doStartTransaction() throws JMSException {
> if (!getTransactionContext().isInXATransaction()) {
> throw new JMSException("Session's XAResource has not been enlisted in a distributed transaction.");
> }
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)