immutant

http://immutant.org Note: dev discussion happens in #immutant on FreeNode IRC.
2016-06-29T15:00:09.000202Z

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

richiardiandrea 2016-06-29T15:01:10.000203Z

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

2016-06-29T15:01:42.000204Z

your wait-for-close?

richiardiandrea 2016-06-29T15:02:10.000205Z

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

2016-06-29T15:02:41.000206Z

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

richiardiandrea 2016-06-29T15:04:30.000207Z

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

2016-06-29T15:08:23.000208Z

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

2016-06-29T15:08:54.000210Z

I'll try it locally

richiardiandrea 2016-06-29T15:10:12.000211Z

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

richiardiandrea 2016-06-29T15:10:22.000212Z

To have the same situation as here

2016-06-29T15:11:09.000213Z

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

2016-06-29T15:11:47.000214Z

I tried this:

2016-06-29T15:11:51.000215Z

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

2016-06-29T15:12:17.000216Z

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

richiardiandrea 2016-06-29T15:16:14.000217Z

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

richiardiandrea 2016-06-29T15:16:50.000218Z

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

2016-06-29T15:17:11.000219Z

what does work is:

2016-06-29T15:17:14.000220Z

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

richiardiandrea 2016-06-29T15:17:41.000221Z

Ah

2016-06-29T15:17:50.000222Z

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

2016-06-29T15:18:00.000223Z

so there are still non-daemon threads running somewhere

2016-06-29T15:18:10.000224Z

ah, it's likely the agent threadpool

2016-06-29T15:18:20.000225Z

let me (shutdown-agents) to see

richiardiandrea 2016-06-29T15:18:34.000226Z

Yes I have to do shutdown-agents as well

2016-06-29T15:19:05.000227Z

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

2016-06-29T15:20:09.000229Z

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

richiardiandrea 2016-06-29T15:20:35.000230Z

Great good to know

2016-06-29T15:21:04.000231Z

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

richiardiandrea 2016-06-29T15:21:18.000232Z

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

2016-06-29T15:21:48.000233Z

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

2016-06-29T15:21:55.000234Z

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

richiardiandrea 2016-06-29T15:22:02.000235Z

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

richiardiandrea 2016-06-29T15:22:07.000236Z

Great ok

2016-06-29T15:22:17.000237Z

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

richiardiandrea 2016-06-29T15:22:34.000239Z

Awesome

2016-06-29T15:22:37.000240Z

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

richiardiandrea 2016-06-29T15:22:44.000241Z

Tnx a lot

2016-06-29T15:22:52.000242Z

my pleasure!

jrotenberg 2016-06-29T21:41:51.000244Z

Could not locate immutang/...

jrotenberg 2016-06-29T21:41:54.000245Z

immutang!

2016-06-29T21:42:38.000246Z

it's a merging of wu tang clan and immutant

2016-06-29T21:42:50.000247Z

or maybe powdered orange drink

jrotenberg 2016-06-29T21:48:56.000248Z

i was thinking the drink

2016-06-29T21:57:46.000249Z

I'm always thinking about drink

jrotenberg 2016-06-29T22:31:09.000250Z

same