zhfeng commented on issue #346: compensation method invoke before compensable 
method
URL: 
https://github.com/apache/servicecomb-saga/issues/346#issuecomment-443079952
 
 
   It looks like the timeout happens during the HotelBookingService is sleeping 
? And the compensate method was invoked before the booking is finished. So it 
maybe need to add a lock to check if the transaction is cancelled.
   
   ```
   void order(HotelBooking booking) {
   ...
       locker.lock();
       if (! isCancelled) {
            doBooking();
       } else {
            throw Exception("transaction is cancelled");
       }
       locker.unlock();
   }
   
   void cancel(HotelBooking booking) {
        locker.lock();
        isCancelled = true;
        doCancel();
        locker.unlock();
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to