Fork me on GitHub
#component
<
2016-09-26
>
donaldball21:09:26

Hi component friends. I just got an interesting stacktrace from a component usage to which I’m not sure the best way to respond.

donaldball21:09:04

In this app, I’m running a persistent system that would like to be able to shutdown cleanly when it receives a SIGTERM. The bootup is, in essence:

donaldball21:09:15

(defn -main
  []
  (let [system (volatile! (system/create-system))
        runtime (Runtime/getRuntime)
        shutdown? (promise)]
    (.addShutdownHook runtime
                      (Thread. (fn []
                                 (component/stop-system @system)
                                 (deliver shutdown? true))))
    (vswap! system component/start-system)
    @shutdown?))

donaldball21:09:34

It… usually works as I expect, but once I got this:

donaldball21:09:51

Exception in thread "Thread-1" java.lang.NoClassDefFoundError: com/stuartsierra/component$update_system_reverse$fn__1373
        at com.stuartsierra.component$update_system_reverse.invokeStatic(component.cljc:143)
        at com.stuartsierra.component$update_system_reverse.doInvoke(component.cljc:143)
        at clojure.lang.RestFn.invoke(RestFn.java:445)
        at com.stuartsierra.component$stop_system.invokeStatic(component.cljc:173)
        at com.stuartsierra.component$stop_system.invoke(component.cljc:165)
        at com.stuartsierra.component$stop_system.invokeStatic(component.cljc:171)
        at bleach.system$stop.invokeStatic(system.clj:177)
        at bleach.main$fn__6067$fn__6068.invoke(main.clj:94)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.stuartsierra.component$update_system_reverse$fn__1373
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)

donaldball21:09:34

Which I presume indicates a race between the classloader disposing things and the shutdown hook being invoked

donaldball21:09:21

I would appreciate any thoughts on how to work around or better implement this

hiredman22:09:33

I would very much doubt that

hiredman22:09:09

my guess would be either some kind of weird aot thing or some kind of weird reloaded thing