Skip to content

Commit

Permalink
May be a (delayed) lock on mid, might fix the issue. Presuming that i…
Browse files Browse the repository at this point in the history
…t is some race condition.
  • Loading branch information
mihxil committed Nov 29, 2024
1 parent f39b69e commit 44c957d
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static <K extends Serializable> LockHolderCloser<K> acquireLock(
locks.remove(key);
continue;
}
closer = new LockHolderCloser<>(nanoStart, locks, holder);
closer = new LockHolderCloser<>(nanoStart, locks, holder, true);
if (holder.lock.isLocked() && !holder.lock.isHeldByCurrentThread()) {
log.debug("There are already threads ({}) for {}, waiting", holder.lock.getQueueLength(), key);
alreadyWaiting = true;
Expand Down Expand Up @@ -327,7 +327,8 @@ private static <K extends Serializable> void releaseLock(
final @NonNull K key,
final @NonNull String reason,
final @NonNull Map<K, LockHolder<K>> locks,
final @NonNull LockHolder<K> lock) {
final @NonNull LockHolder<K> lock,
final boolean checkIfCurrentThread) {
synchronized (locks) {
if (lock.lock.getHoldCount() == 1) {
if (!lock.lock.hasQueuedThreads()) {
Expand All @@ -342,7 +343,7 @@ private static <K extends Serializable> void releaseLock(
Slf4jHelper.log(log, duration.compareTo(lock.warnTime)> 0 ? Level.WARN : Level.DEBUG,
"Released lock for {} ({}) in {}", key, reason, Duration.ofNanos(System.nanoTime() - nanoStart));
}
if (lock.lock.isHeldByCurrentThread()) { // MSE-4946
if (! checkIfCurrentThread || lock.lock.isHeldByCurrentThread()) { // MSE-4946
HOLDS.get().remove(lock);
lock.lock.unlock();
} else {
Expand Down Expand Up @@ -456,19 +457,25 @@ public static class LockHolderCloser<K extends Serializable> implements AutoClos

final long nanoStart;

@With
final boolean checkIfCurrentThread;

final @NonNull Map<K, LockHolder<K>> locks;

private LockHolderCloser(
final long nanoStart,
@NonNull Map<K, LockHolder<K>> locks,
@NonNull LockHolder<K> lockHolder) {
@NonNull LockHolder<K> lockHolder,
final boolean checkIfCurrentThread) {
this.nanoStart = nanoStart;
this.locks = locks;
this.lockHolder = lockHolder;
this.checkIfCurrentThread = checkIfCurrentThread;
}

@Override
public void close() {
releaseLock(nanoStart, lockHolder.key, lockHolder.reason, locks, lockHolder);
releaseLock(nanoStart, lockHolder.key, lockHolder.reason, locks, lockHolder, checkIfCurrentThread);
}
}

Expand Down

0 comments on commit 44c957d

Please sign in to comment.