Hook uses `shutdown-agents` #136

cemerick opened this Issue Sep 7, 2012 · 4 comments


None yet
2 participants

cemerick commented Sep 7, 2012

With :hooks [leiningen.cljsbuild] added, running my application under lein trampoline (common on heroku and elsewhere) results in the same exception reported in technomancy/leiningen#262:

    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768)
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:92)
    at clojure.core$future_call.invoke(core.clj:6212)
    at ring.middleware.gzip$piped_gzipped_input_stream.invoke(gzip.clj:13)

In my case, the future is being spun off by amalloy/ring-gzip-middleware, but that's neither here nor there.

All's well if the hook isn't present, or if the app isn't run with trampoline. As a workaround, I just put the cljsbuild hook in a separate profile (since it certainly doesn't need to be spun up at deploy-time anyway).

Presumably, the cljsbuild hook needs the same salve as what fixed technomancy/leiningen#262. (Note that my -main function does block, so I don't think that's a differentiating factor.)

Addendum: This is due to the plugin calling shutdown-agents, which makes any later use of futures and agents fail.


cemerick commented Sep 7, 2012

Correction: the workaround is to move the actual :plugin reference to cljsbuild to a different profile, since hooks are automatically applied from plugins in Leiningen 2.


emezeske commented Sep 8, 2012

I don't understand what it is about setting up the hooks that's causing that error, so I'm having trouble determining whether this is something that I could improve in lein-cljsbuild. Do you know exactly what is causing things to go awry?


cemerick commented Sep 10, 2012

Found it: https://github.com/emezeske/lein-cljsbuild/blob/master/plugin/src/leiningen/cljsbuild.clj#L52

Calling shutdown-agents means any and all futures and agent sends will fail afterwards. This is obviously not going to end well if (as is typical when using trampoline) the current process is serving one's app.

This is bad idea in general, and is actually unrelated to trampoline (subject updated); it only exposed the issue because cljsbuild's processing happened to come before later future/agent usage in the same process. cljsbuild could easily be involved in a multi-step build process, and later stages (e.g. lein do cljsbuild once, other-plugin, other-plugin2) may very well use futures and agents to do who-knows-what. Stuff like this should be left to Leiningen. I'll add a PR that drops the call, which eliminates the exception for me, using Leiningen 2.0-preview10.

Based on technomancy's comment in technomancy/leiningen#262, I'd presume this shutdown-agents call is no longer necessary, even in 1.7, but I'm in no position to verify that right now.


emezeske commented Sep 11, 2012

Seems reasonable to me. Thanks for the detailed analysis.

I'll make sure this goes out in the next release!

emezeske closed this in a99fe27 Oct 1, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment