component

donaldball 2016-09-26T21:02:26.000028Z

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

donaldball 2016-09-26T21:03:04.000029Z

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:

donaldball 2016-09-26T21:03:15.000030Z

(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?))

donaldball 2016-09-26T21:03:34.000031Z

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

donaldball 2016-09-26T21:03:51.000032Z

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)

donaldball 2016-09-26T21:04:34.000033Z

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

donaldball 2016-09-26T21:05:21.000034Z

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

2016-09-26T22:06:33.000036Z

I would very much doubt that

2016-09-26T22:07:09.000037Z

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