Fork me on GitHub
#immutant
<
2016-06-28
>
richiardiandrea20:06:25

Sorry for the crosspost but is there a way to wait for the immutant server to close? akin to aleph's wait-for-close https://github.com/ztellman/aleph/blob/master/src/aleph/netty.clj#L732

tcrawley20:06:53

@richiardiandrea: what does wait-for-close do? block until the server exits?

tcrawley20:06:45

the web server doesn't close until you close it, so I'm curious what your need really is?

richiardiandrea20:06:45

Yes it does block the main Thread

jcrossley320:06:55

@richiardiandrea: immutant.util/at-exit may help you. also, maybe look at https://issues.jboss.org/browse/IMMUTANT-605

richiardiandrea20:06:35

Oh ok I'll have a look

richiardiandrea20:06:56

It is a common problem when Java is executing all daemon threads, which are not stopping the JVM to shutdown...checking checking...thanks a lot

jcrossley320:06:36

sure thing. if that doesn't meet all your needs, holler and maybe we can figure something out

richiardiandrea21:06:47

thanks! I think I will need to wait on a promise that will be filled on at-exit

richiardiandrea22:06:26

Simple enough 😄

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

jcrossley322:06:00

@richiardiandrea: so i assume it makes no sense for you to do whatever you're waiting to do in the at-exit itself?

richiardiandrea22:06:20

no I basically need to block the main thread from exiting

richiardiandrea22:06:08

an alternative would be to have non-daemon threads running, so if the server can be set to have non-daemon threads

richiardiandrea22:06:20

I would not even need the above workaround

jcrossley322:06:07

i think i've seen some xnio daemon option somewhere. not sure how exposed it is.

richiardiandrea22:06:13

they actually have the opposite problem there 😉

jcrossley322:06:10

but it appears its default value is false

richiardiandrea22:06:15

spotted 😉

jcrossley322:06:53

ah-hah! 🙂

jcrossley322:06:19

lemme see if that's still needed

jcrossley322:06:31

@richiardiandrea: all tests are passing for me locally without setting that option. i've only tested in one container, and i'd like to confer with @tcrawley that we're actually testing the condition that code is affecting, but i think we can safely remove that. which is good, cuz i don't like that we're setting it.

jcrossley322:06:58

yeah, i'm almost sure that was a workaround for a bug now obsolete with the versions of undertow & xnio we're currently using

richiardiandrea22:06:09

ok good, I'd be glad to try it, let me know when it is up ok?

richiardiandrea22:06:56

just one thing to keep in mind is that now the JVM won't exit until the server shuts down

jcrossley323:06:41

i'm not seeing that locally. it's possible something else (undertow?) in the stack is doing it now

richiardiandrea23:06:10

yeah it is possible that this is kind of hidden by the fact that run is executed in -main directly