Github user clebertsuconic commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1102#discussion_r106741245
  
    --- Diff: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/transaction/ProtonTransactionHandler.java
 ---
    @@ -78,44 +82,68 @@ public void onMessage(Delivery delivery) throws 
ActiveMQAMQPException {
                 Binary txID = sessionSPI.newTransaction();
                 Declared declared = new Declared();
                 declared.setTxnId(txID);
    -            delivery.disposition(declared);
    +            synchronized (connection.getLock()) {
    +               delivery.disposition(declared);
    +            }
              } else if (action instanceof Discharge) {
                 Discharge discharge = (Discharge) action;
     
                 Binary txID = discharge.getTxnId();
    -            sessionSPI.dischargeTx(txID);
    +            ProtonTransactionImpl tx = 
(ProtonTransactionImpl)sessionSPI.getTransaction(txID, true);
    +            tx.discharge();
    +
                 if (discharge.getFail()) {
                    try {
    -                  sessionSPI.rollbackTX(txID, true);
    -                  delivery.disposition(new Accepted());
    +                  tx.rollback();
    +                  synchronized (connection.getLock()) {
    +                     delivery.disposition(new Accepted());
    +                  }
    +                  connection.flush();
                    } catch (Exception e) {
    +                  log.warn(e.getMessage(), e);
                       throw 
ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorRollingbackCoordinator(e.getMessage());
                    }
                 } else {
                    try {
    -                  sessionSPI.commitTX(txID);
    -                  delivery.disposition(new Accepted());
    +                  tx.commit();
    +                  synchronized (connection.getLock()) {
    +                     delivery.disposition(new Accepted());
    +                  }
    +                  connection.flush();
                    } catch (ActiveMQAMQPException amqpE) {
    +                  log.warn(amqpE.getMessage(), amqpE);
                       throw amqpE;
                    } catch (Exception e) {
    +                  log.warn(e.getMessage(), e);
                       throw 
ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCommittingCoordinator(e.getMessage());
                    }
                 }
     
                 // Replenish coordinator receiver credit on exhaustion so 
sender can continue
                 // transaction declare and discahrge operations.
    -            if (receiver.getCredit() == 0) {
    -               receiver.flow(DEFAULT_COORDINATOR_CREDIT);
    +            synchronized (connection.getLock()) {
    --- End diff --
    
    I have checked and there are no locks being held...
    
    This kind of pattern is being used everywhere else we use proton. We need 
to make sure nothing is changed from an incoming packet. so I need the lock 
here.
    
    
    I'm not sure if that's what you meant.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to