Fix stop-app in the interactive CLI without Actuator or JMX#15697
Closed
jamesfredley wants to merge 1 commit into
Closed
Fix stop-app in the interactive CLI without Actuator or JMX#15697jamesfredley wants to merge 1 commit into
jamesfredley wants to merge 1 commit into
Conversation
The base profile stop-app command relied on JMX (via com.sun.tools.attach.VirtualMachine and the management-agent.jar that was removed in Java 9+) with an HTTP fallback to the Spring Boot Actuator /actuator/shutdown endpoint. The JMX path is broken on modern JDKs and the Actuator endpoint is disabled by default, so stop-app failed with a FileNotFoundException against /actuator/shutdown even though the application was running. In the interactive shell, run-app starts the application as an asynchronous Gradle bootRun build whose cancellation token was only reachable through the run-app command's ExecutionContext. This adds a RunningApplicationRegistry that tracks the running build's CancellationTokenSource so that stop-app can cancel it directly - the same mechanism CTRL-C already uses - without shutting down the CLI. - Add RunningApplicationRegistry to track running bootRun builds. - GradleUtil.wireCancellationSupport now returns the token source (created via the public GradleConnector.newCancellationTokenSource() instead of the internal DefaultCancellationTokenSource) and a new runBuildWithConsoleOutput overload registers and deregisters it. - GradleInvoker tracks only the bootRun task for stop support. - Rewrite stop-app to cancel the running build via the registry and wait for it to stop; remove the obsolete port/host flags. - run-app no longer enables the Actuator shutdown endpoint and its shutdown hook cancels via the registry directly. - Update the reference and getting-started docs. Fixes apache#13695 Assisted-by: opencode:claude-opus-4-8
Contributor
Author
|
Superseded by #15698 (branch pushed to apache/grails-core instead of a fork). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13695
Problem
stop-appin the interactive Grails shell does not work. The base profilestop-appcommand tries two mechanisms, both of which fail on a modern setup:com.sun.tools.attach.VirtualMachine, loadingmanagement-agent.jar- that jar was removed in Java 9+, and the code usesjavax.*. This silently fails on JDK 17/21./actuator/shutdownendpoint - disabled by default, so it throwsFileNotFoundException(HTTP 404), reporting "Application not running" even though it is.Enabling the Actuator shutdown endpoint is not an acceptable fix: it is intrusive and affects production for the sake of a development-time
stop-app.Approach (CLI only, no Actuator, no JMX)
In the interactive shell,
run-appstarts the application as an asynchronous GradlebootRunbuild. That build already has a Gradle Tooling APICancellationTokenSource- it is what CTRL-C uses to stop the app. The problem is that the token was only reachable through therun-appcommand'sExecutionContext, sostop-app(a separateExecutionContextin the same CLI JVM) had no handle to it.This PR introduces a small shared registry so
stop-appcan cancel the running build directly, withoutPOOL.shutdownNow()(which would kill the executor and block re-running) and without exiting the CLI.Changes
RunningApplicationRegistry(grails-shell-cli) - tracks theCancellationTokenSourceof runningrun-appbuilds.stopAll()only requests cancellation; the build deregisters its own token when it finishes.awaitStop(timeout)waits for the build to tear down.GradleUtil-wireCancellationSupportnow returns the token source, created via the publicGradleConnector.newCancellationTokenSource()instead of the internalDefaultCancellationTokenSource. A newrunBuildWithConsoleOutput(context, trackForStop, closure)overload registers/deregisters the token around the build.GradleInvoker- tracks only thebootRuntask (matchesbootRunor:bootRun), so transient builds (compile, test, console) are not affected.stop-app.groovy- rewritten to cancel via the registry and wait for shutdown; obsoleteport/hostflags removed.run-app.groovy- no longer passes-Dgrails.management.endpoints.shutdown.enabled=true(only existed to enable the Actuator endpoint); the JVM shutdown hook now callsRunningApplicationRegistry.stopAll()directly instead of re-invoking thestop-appcommand.stop-appreference and the getting-started running/debugging guide.Tests
RunningApplicationRegistrySpeccovers register/deregister,stopAllrequesting cancellation without removing tokens, resilience when a token throws, andawaitStopsuccess/timeout../gradlew :grails-shell-cli:test --tests "org.grails.cli.gradle.RunningApplicationRegistrySpec"passes.Manual verification still recommended
The forked application JVM is torn down by Gradle when the
bootRunbuild is cancelled (the same path CTRL-C uses). A manual run ofgrails run-app->grails stop-app->grails run-appon JDK 21 (Windows and Linux) is recommended before merge to confirm no orphaned process and that the port is freed.Notes
7.0.x. The linked issue is milestoned for 8.0.0-M3; opening here first per discussion.