Fork me on GitHub
#immutant
<
2016-06-29
>
tcrawley15:06:09

@richiardiandrea: I'm trying to understand what your needs are - would you mind stating your use case?

richiardiandrea15:06:10

@tcrawley: thanks for asking but on my side I solved, see snippet above

tcrawley15:06:42

your wait-for-close?

richiardiandrea15:06:10

Yep, I put this in my main and it blocks until the server exits

tcrawley15:06:41

what is triggering the server to exit? a ^-C? or are you calling web/stop somewhere?

richiardiandrea15:06:30

Yes I call stop as part of the app life cycle, and the start is executed in separate thread

tcrawley15:06:23

hmm. I'm glad that works for you, but it really shouldn't :) Fns registered with at-exit will only be called when the JVM exits

tcrawley15:06:54

I'll try it locally

richiardiandrea15:06:12

Oh, ok...just put a mount defstate and that snippet in the main together with a a mount/start before it

richiardiandrea15:06:22

To have the same situation as here

tcrawley15:06:09

I've never used mount, so wouldn't know where to start :)

tcrawley15:06:47

I tried this:

tcrawley15:06:51

(ns exit.core
  (:require [immutant.web :as web])
  (:gen-class))

(defn wait-for-close
  []
  (let [promise (promise)]
    (immutant.util/at-exit #(deliver promise "please shutdown"))
    @promise))

(defn -main [& args]
  (web/run (fn [req] {:status 200 :body "hi"})
    )
  (future
    (Thread/sleep 5000)
    (println "Stopping")
    (web/stop))
  (wait-for-close)
  (println "done"))

tcrawley15:06:17

and it doesn't exit after printing "Stopping". I don't see "done"

richiardiandrea15:06:14

So maybe in my case is working because I am also exiting the jvm

richiardiandrea15:06:50

I haven't paid attention too much to that distinction until you told me

tcrawley15:06:11

what does work is:

tcrawley15:06:14

(ns exit.core
  (:require [immutant.web :as web])
  (:gen-class))

(defn wait-for-close
  []
  (let [promise (promise)]
    (immutant.util/at-exit #(do (deliver promise "please shutdown")
                                (println "AT-EXIT")))
    @promise))

(defn -main [& args]
  (web/run (fn [req] {:status 200 :body "hi"})
    )
  (future
    (Thread/sleep 5000)
    (println "Stopping")
    ;;(web/stop)
    (immutant.util/reset))
  (wait-for-close)
  (println "done"))

tcrawley15:06:50

well, I see "Stopping AT-EXIT done", but the JVM doesn't exit

tcrawley15:06:00

so there are still non-daemon threads running somewhere

tcrawley15:06:10

ah, it's likely the agent threadpool

tcrawley15:06:20

let me (shutdown-agents) to see

richiardiandrea15:06:34

Yes I have to do shutdown-agents as well

tcrawley15:06:05

yeah, that does the trick. I just (shutdown-agents) after (wait-for-close)

tcrawley15:06:09

immutant.util/reset is designed for repl use, and basically stops all of the running Immutant services, and triggers all the at-exit fns

richiardiandrea15:06:35

Great good to know

tcrawley15:06:04

so this will work once you add in immutant messaging, caching, etc.

richiardiandrea15:06:18

Does it release resources as well? In a reloaded workflow this is important as well...

tcrawley15:06:48

it should shut down all the various thread pools that any service starts, so you should be good

tcrawley15:06:55

if you see a leak, that's a bug we should fix

richiardiandrea15:06:02

I mean don't prevent the GC of pools and friends

tcrawley15:06:17

we use that in our testing, and haven't noticed any leaks

tcrawley15:06:37

but we shouldn't be holding any hard references after reset

tcrawley15:06:52

my pleasure!

jrotenberg21:06:51

Could not locate immutang/...

tcrawley21:06:38

it's a merging of wu tang clan and immutant

tcrawley21:06:50

or maybe powdered orange drink

jrotenberg21:06:56

i was thinking the drink

tcrawley21:06:46

I'm always thinking about drink