[#4659] Wrap LockingRepository#doLoadOrCreate try-catch in outer try-catch to ensure locks are released#4679
Merged
Conversation
Wrap try-catch in another try-catch to ensure locks are released in case the aggregate was deleted and at the same time another thread tried to create-if-missing the deleted aggregate. Without the outer try-catch, the rethrowing of the deleted exception does not result in a lock releasing. By moving the catch-all catch that released the lock to an outer try-catch, we are certain the lock is also released for this scenario. #4659
hatzlj
approved these changes
Jun 22, 2026
hatzlj
left a comment
Contributor
There was a problem hiding this comment.
a cosmetic finding in the LockingRepositoryTest, otherwise LGTM
Minor cosmetic test change #4659
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request moves the catch-all
catch(Exception)to be an outer try-catch instead of being part of the single try-catch.In doing so, we ascertain that the exception rethrown when
isExactAggregateNotFound(Class<? extends AggregateNotFoundException>)is false is caught, resulting in the lock to be released.If we do not, we can accidentally keep a lock for an aggregate that's been marked deleted, but is hit with a quick subsequent create-if-missing invocation.
In doing the above, this PR resolves #4659.