This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch mvnd-1.x in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
commit fc2720519db86a39fadc2649d6b313384d766fc1 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Sun Oct 25 20:49:06 2026 +0100 Only cancel a daemon that is running a build The message receiver outlives the build. When the client closes its socket after BuildFinished, the resulting RecoverableMessageIOException set the state to Canceled after the build had already returned the daemon to Idle. A canceled daemon is never reused and stops itself, so the next client started a second daemon. (cherry picked from commit cdd04b4face7a3d01fe677926d1e7abe527b7e5d) --- .../main/java/org/mvndaemon/mvnd/daemon/Server.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java index 68eb487e..8c2aa0f7 100644 --- a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java +++ b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java @@ -617,7 +617,7 @@ public class Server implements AutoCloseable, Runnable { } LOGGER.info("Received message: {}", message); if (message == Message.BareMessage.CANCEL_BUILD_SINGLETON) { - updateState(Canceled); + cancelRunningBuild(); return; } else if (message instanceof Message.InputData) { daemonInputStream.addInputData(((Message.InputData) message).getData()); @@ -629,7 +629,7 @@ public class Server implements AutoCloseable, Runnable { } } } catch (DaemonException.RecoverableMessageIOException t) { - updateState(Canceled); + cancelRunningBuild(); } catch (Throwable t) { updateState(Broken); LOGGER.error("Error receiving events", t); @@ -712,6 +712,22 @@ public class Server implements AutoCloseable, Runnable { } } + /** + * The receiver thread outlives the build: the client closing its socket after {@code BuildFinished} would + * otherwise turn an idle daemon into a canceled one, which no client reuses and which stops itself. + */ + private void cancelRunningBuild() { + stateLock.lock(); + try { + DaemonState state = getState(); + if (state == Busy || state == StopRequested) { + updateState(Canceled); + } + } finally { + stateLock.unlock(); + } + } + private void updateState(DaemonState state) { if (getState() != state) { LOGGER.info("Updating state to: {}", state);
