gnodet commented on code in PR #1927:
URL: https://github.com/apache/maven-mvnd/pull/1927#discussion_r4792865953
##########
client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java:
##########
@@ -124,6 +135,81 @@ public DaemonClientConnection connect(ClientOutput output)
{
return startDaemon(daemonId, output);
}
+ private DaemonClientConnection connectWithLimit(
+ ClientOutput output, DaemonCompatibilitySpec constraint, int
maximum) {
+ Path lockPath = registry.getRegistryFile()
+ .resolveSibling(registry.getRegistryFile().getFileName() +
".connect.lock");
+ boolean waiting = false;
+ AtomicBoolean canceled = new AtomicBoolean();
+ output.setDaemonDispatch(message -> {
+ if (message == Message.BareMessage.CANCEL_BUILD_SINGLETON) {
+ canceled.set(true);
+ }
+ });
+ try (FileChannel channel = FileChannel.open(
+ lockPath,
+ StandardOpenOption.CREATE,
+ StandardOpenOption.WRITE,
+ java.nio.file.LinkOption.NOFOLLOW_LINKS)) {
+ while (true) {
+ if (canceled.get() || Thread.currentThread().isInterrupted()) {
+ throw new DaemonException.InterruptedException(new
InterruptedException());
+ }
+ // A separate lock allows the new daemon to register while
startup is serialized.
+ try (FileLock lock = tryConnectLock(channel)) {
+ if (lock != null) {
+ List<DaemonInfo> live = new ArrayList<>();
+ for (DaemonInfo daemon : registry.getAll()) {
+ if (isAlive(daemon.getPid())) {
+ live.add(daemon);
+ } else {
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Good - the code proactively cleans up stale registry entries for dead
processes. This prevents the limit from being artificially constrained by
zombie entries.
##########
client/src/test/java/org/mvndaemon/mvnd/client/DaemonConnectorTest.java:
##########
@@ -34,6 +47,191 @@
public class DaemonConnectorTest {
+ @Test
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
Excellent test coverage! The tests comprehensively cover:
- Concurrent startup serialization and limit enforcement
- Cancellation during wait
- Error cases (incompatible daemons, negative limits)
- Reuse of busy daemons that become idle
The use of CountDownLatch to coordinate concurrent threads and the mock
connector pattern make the tests both readable and reliable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]