Checked exceptions and not released locks in LockingRepository

Hi !

First of all, thanks for making such a great framework which facilitates event sourcing so much !

Currently we are working on some issue with not released aggregate’s locks. We are using EventSourcingRepository with PessimisticLockManager.
A few times we found on our dev instances situation when many (like 15) threads are locked on some aggregate’s lock trying to load it. It’s not a deadlock (which are handled properly by Axon itself), because only threads which are doing something, are those thread which are locked. So it’s stuck.

It’s difficult to say why this happend so I started to look through Axon sources and found some things, which I do not understand:

1 - LockingRepository in “add” and “load” methods releases a lock only when RuntimeException is catched. If it’s checked exception it does nothin and LockCleaningListener is not registered, so it’s a potential situation with not released aggregate’s lock.
2 - In NestableUnitOfWork in commit method, Axon does rollback (and perform cleanup which releases locks!) only when there is RuntimeException. What if it’s not RuntimeException ?
3 - NestableUnitOfWork even when cought RuntimeException, when method doRollback() execution throws another exception, performCleanup method is not executed neither.

We are using Axon with Scala and Scala doesn’t have checked exceptions. So it’s very easy to throw (of course not intentionally) exception from event-sourced method in aggregate while loading it, which is not a subclass of RuntimeException.

We are using axon 2.4.


Hi Maciej,

thanks for the comment/warning. I wasn’t aware of this behavior in Scala.
We’ll make sure Axon will catch all exceptions, even when no checked exceptions are declared.