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/16 10:11:02 UTC
(maven-resolver) 30/34: 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 master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit dc2c84ff9de73ed5d707b7f5c1f3e23469d9b615
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.
---
.../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 b7ae0a03f..6d5470fd2 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);
});
}
}