You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/06/07 09:50:03 UTC
(maven-resolver) 02/06: Fix IpcServer unlock — replace TOCTOU isEmpty+remove with atomic compute
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch gnodet/thread-safety-fixes
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit 811ba046bb52d0832b5fa5639bd67a12c6014b87
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sun Jun 7 09:43:56 2026 +0000
Fix IpcServer unlock — replace TOCTOU isEmpty+remove with atomic compute
The unlock() path had a race: after checking l.isEmpty(), another
thread could computeIfAbsent and re-use the same Lock object, then
the remove(l.key, l) would remove a Lock that now has holders.
Replace the two-step isEmpty() check + remove() with a single
locks.compute() call that atomically checks emptiness and removes.
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../src/main/java/org/eclipse/aether/named/ipc/IpcServer.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
index 9fb1abb88..a6b0a00f1 100644
--- a/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
+++ b/maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java
@@ -497,9 +497,7 @@ public class IpcServer {
.map(k -> IpcServer.this.locks.computeIfAbsent(k, Lock::new))
.forEach(l -> {
l.unlock(this);
- if (l.isEmpty()) {
- IpcServer.this.locks.remove(l.key, l);
- }
+ IpcServer.this.locks.compute(l.key, (k, v) -> (v == l && v.isEmpty()) ? null : v);
});
}
}