Fork me on GitHub
#xtdb
<
2021-11-24
>
richiardiandrea18:11:14

> richiardiandrea: Is there a way to stop a Jetty server started with :crux.http-server/server? > I use the reloaded pattern and I do call .close on the node on stop but it seems the Http server is still running on restart and I get back a Address already in use error Hi there, I wanted to find if there was an answer to the question above. I could not find it and I am still receiving

Execution error (BindException) at  (Net.java:-2).
Address already in use
When restarting the app cause Jetty remains started - I have also checked the CruxNode defrecord but I don't see the http server...any hint?

richiardiandrea18:11:22

I think I found it under (:server (:crux.http-server/server @(:!system node))) Please let me know if this is considered an anti-pattern 😄

refset16:11:26

hey 🙂 sorry to be late to the party here....so are you saying that you had held on to a reference to the http server by looking it up inside the node and storing it somewhere in your app state, preventing it from getting GC'd?

refset17:11:56

Or (on second reading) are you saying that you have a workaround you're happy enough with for the moment?

refset17:11:36

which JVM platform + OS are you using?

richiardiandrea17:11:47

Hey Jeremy yes sorry that was late here and I was definitely tired :D So basically I needed a way to shut down the jetty server launched as a module I found the above as workaround, and in my component start I can now:

(assoc :node node
               :http-server (-> node
                                :!system
                                deref
                                :crux.http-server/server
                                :server))
And in the component stop:
(:import
   org.eclipse.jetty.server.Server)

...
(when (and http-server
             (or (not (.isStopping ^Server http-server)) (not (.isStopped ^Server http-server))))
    (.stop ^Server http-server))
I think the ideal solution would be to have :close-fn on the node stop the server for me...I am calling it this way:
(when (and node (not (:closed? node))) (let [close-fn (:close-fn node)] (close-fn))) 
Do you think it is worth a GitHub issue?

refset18:11:57

The server record implements Closeable already (which runs .stop) and the xtdb.system wiring should be .close-ing everything properly...so I'm not sure why it's not actually stopping for you https://github.com/xtdb/xtdb/blob/master/modules/http-server/src/xtdb/http_server.clj#L238

refset18:11:52

> which JVM platform + OS are you using? (^bump)

refset18:11:18

are you leaving a pause between stopping and restarting? Looking at https://javadoc.io/doc/org.eclipse.jetty/jetty-server/latest/org.eclipse.jetty.server/org/eclipse/jetty/server/Server.html I see that STOPPING is listed as a possible AbstractLifeCycle field value :thinking_face:

richiardiandrea19:11:05

I am on JVM plus linux but let me verify in isolation what is going on - your link clearly shows that you it is calling .stop there

👍 1