This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch maven-resolver-1.9.x
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/maven-resolver-1.9.x by this
push:
new b4fb00a83 [1.9.x] Prune FileLockNamedLock thread entries that hold no
step
b4fb00a83 is described below
commit b4fb00a83d3c2ef6136bfa02c8d4473dc97c012a
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 8 23:26:29 2026 +0100
[1.9.x] Prune FileLockNamedLock thread entries that hold no step
threadSteps kept an entry for every thread that ever used the lock,
including
threads whose attempt timed out, for the lock's lifetime.
---
.../aether/named/support/FileLockNamedLock.java | 41 ++++++++++++++++++----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git
a/maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/FileLockNamedLock.java
b/maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/FileLockNamedLock.java
index 0eaa73974..a2d103c9d 100644
---
a/maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/FileLockNamedLock.java
+++
b/maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/FileLockNamedLock.java
@@ -84,12 +84,36 @@ public final class FileLockNamedLock extends
NamedLockSupport {
@Override
protected boolean doLockShared(final long time, final TimeUnit unit)
throws InterruptedException {
- return retry(time, unit, RETRY_SLEEP_MILLIS, () ->
doLockSharedPerform(time, unit), null, false);
+ boolean locked = retry(time, unit, RETRY_SLEEP_MILLIS, () ->
doLockSharedPerform(time, unit), null, false);
+ if (!locked) {
+ forgetThreadWithoutSteps();
+ }
+ return locked;
}
@Override
protected boolean doLockExclusively(final long time, final TimeUnit unit)
throws InterruptedException {
- return retry(time, unit, RETRY_SLEEP_MILLIS, () ->
doLockExclusivelyPerform(time, unit), null, false);
+ boolean locked = retry(time, unit, RETRY_SLEEP_MILLIS, () ->
doLockExclusivelyPerform(time, unit), null, false);
+ if (!locked) {
+ forgetThreadWithoutSteps();
+ }
+ return locked;
+ }
+
+ /**
+ * Drops the current thread's entry if it holds no step, so that the map
does not retain threads that no longer
+ * use this lock.
+ */
+ private void forgetThreadWithoutSteps() {
+ criticalRegion.lock();
+ try {
+ Deque<Boolean> steps = threadSteps.get(Thread.currentThread());
+ if (steps != null && steps.isEmpty()) {
+ threadSteps.remove(Thread.currentThread());
+ }
+ } finally {
+ criticalRegion.unlock();
+ }
}
private Boolean doLockSharedPerform(final long time, final TimeUnit unit)
throws InterruptedException {
@@ -177,11 +201,14 @@ public final class FileLockNamedLock extends
NamedLockSupport {
throw new IllegalStateException("Wrong API usage: unlock
without lock");
}
steps.pop();
- if (steps.isEmpty() && !anyOtherThreadHasSteps()) {
- try {
- fileLockRef.getAndSet(null).release();
- } catch (IOException e) {
- throw new UncheckedIOException(e);
+ if (steps.isEmpty()) {
+ threadSteps.remove(Thread.currentThread());
+ if (!anyOtherThreadHasSteps()) {
+ try {
+ fileLockRef.getAndSet(null).release();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
}
}
} finally {