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:
committed by
Gary Russell
parent
70f6ceb5b9
commit
ddab28a06f
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user