Fix pattern how Lock.unlock() is used

Related to https://build.spring.io/browse/INT-MAIN-84/

The `lock.unlock()` must be called in the `finally` block of the
nested `try..catch`, not in the outer which may just fail on `lock.lockInterruptibly()`
in which case there is just not going to be anything we can `unlock()` in the end

**Cherry-pick to `5.4.x` & `5.3.x`**
This commit is contained in:
Artem Bilan
2021-07-19 16:36:42 -04:00
committed by Gary Russell
parent 70f6ceb5b9
commit ddab28a06f
2 changed files with 13 additions and 12 deletions

View File

@@ -514,19 +514,19 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
boolean noOutput = true;
try {
lock.lockInterruptibly();
try {
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
}
finally {
if (noOutput || !this.releaseLockBeforeSend) {
lock.unlock();
}
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new MessageHandlingException(message, "Interrupted getting lock in the [" + this + ']', e);
}
try {
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
}
finally {
if (noOutput || !this.releaseLockBeforeSend) {
lock.unlock();
}
}
}
private boolean processMessageForGroup(Message<?> message, Object correlationKey, UUID groupIdUuid, Lock lock) {