Repository navigation
Shut down Clojure agents after compilation - #69
Merged
Merged
Conversation
dgshep
marked this pull request as ready for review
November 16, 2026 22:25
dgshep
requested review from
DanielThomas,
OdysseusLives,
chali and
rpalcolea
as code owners
November 16, 2026 22:25
chali
approved these changes
Nov 17, 2026
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.
Problem
ClojureCompileforks aclojure.mainJVM to runclojuresque.tasks.compile/main. If loading a namespace during compilation callssend-off(for example, an async logger), Clojure creates non-daemonclojure-agent-send-off-poolthreads. Nothing callsshutdown-agents, so after the compiler script finishes, the idle pool keeps the forked JVM alive for its 60-second keepalive. Each affected compile therefore takes about a minute longer than necessary.Fix
compile.cljwraps the compile/require loop intry/finallyand calls(shutdown-agents)in thefinally. This covers both successful and failed compiles:true, and compiler exceptions still propagate unchanged.System/exitand no timeout.shutdown-agentsshuts the executors down in an orderly way, so agent actions already running when compilation ends do finish. One limitation, standard Clojure behavior when exiting a standalone process: actions still queued behind a running action on the same agent are not run after shutdown. Previously the 60 s linger happened to give them time to finish. Code that sends agent work at namespace-load time and needs it to finish should wait for it, for example withawait.Tests
I extended
NoToolchainNebulaClojurePluginIntegrationSpecwith a test that covers compile and require modes, each on success and on failure. Each case starts a bounded childclojure.mainthat loads the realcompile.clj/util.cljresources through the task's stdin/EDN protocol. The fixture namespace sends an agent action when loaded: the action sleeps 500 ms, then writes a marker file. Failure cases also throw on load.The test asserts that:
true;The test JVM's own agent pools are never shut down.
Red/green:
shutdown-agentsremoved: 4/4 fail because the compiler process doesn't exit within the timeout.shutdownNowon the send-off pool: 4/4 fail because the running action is lost../gradlew check: everything passes locally except the existing Java 8 toolchain specs, which fail only because no local Java 8 is installed (CI installs it).