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:
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.
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.
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?
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.
lein do cljsbuild once, other-plugin, other-plugin2
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.
Seems reasonable to me. Thanks for the detailed analysis.
I'll make sure this goes out in the next release!