Having a hard time with component. Ring handler keeps running after calling (component/stop ...)
. Working off https://github.com/metasoarous/datsys repo
before you stop, does the :http-server key in the system have a :server-stop key under it?
@noisesmith, no:
(keys (:http-server @#'system))
=> (:config :ring-handler :figwheel-system :datomic)
Here is the HttpServer component:
(ns dat.sys.server
(:require [taoensso.timbre :as log :include-macros true]
[com.stuartsierra.component :as component]
[org.httpkit.server :refer (run-server)]))
(defrecord HttpServer [config ring-handler server-stop]
component/Lifecycle
(start [component]
(if server-stop
component
(let [component (component/stop component)
port (-> config :server :port)
server-stop (run-server (:handler ring-handler) {:port port})]
(log/info "HTTP server started on port: " port)
(assoc component :server-stop server-stop))))
(stop [component]
(when server-stop (server-stop))
(log/debug "HTTP server stopped")
(assoc component :server-stop nil)))
(defn new-http-server []
(map->HttpServer {}))
that's confusing, because it clearly attaches the :server-stop
yeah, I saw that
why is it calling stop on iself?
component (component/stop component)
- that's totally weird to me
Seems weird yeah. Maybe to ensure that no server is running before starting?
I don't see the log for "HTTP server started on port: "
but that should be handled by the system - the component's job is to start when you call start, and shut down when you call stop, I don't see why you would stop yourself inside a start method
if the system calls start before stopping you properly, that's the system's job to fix that
When I run (reset)
, I get this output:
(reset)
17-04-16 16:00:31 Petruss-MacBook-Pro.local DEBUG [dat.sys.app:98] - Stopping websocket router
17-04-16 16:00:32 Petruss-MacBook-Pro.local INFO [<http://dat.sys.ws:33|dat.sys.ws:33>] - WebSocket connection stopped
:reloading (dat.sys.server dat.sys.system dat.sys.run user)
17-04-16 16:00:32 Petruss-MacBook-Pro.local INFO [dat.sys.config:59] - Starting config component
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [dat.sys.datomic:42] - Datomic Starting
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [dat.sys.import:12] - Importering data
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [<http://dat.sys.ws:33|dat.sys.ws:33>] - WebSocket connection stopped
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [<http://dat.sys.ws:24|dat.sys.ws:24>] - WebSocket connection started
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [dat.sys.app:88] - Starting websocket router and transaction listener
17-04-16 16:00:33 Petruss-MacBook-Pro.local INFO [dat.sys.dev.figwheel-server:21] - Figwheel server started on port: 2358
=> #<SystemMap>
- this is after changing start method to:
(start [component]
(let [port (-> config :server :port)
server-stop (run-server (:handler ring-handler) {:port port})]
(log/info "HTTP server started on port: " port)
(assoc component :server-stop server-stop)))
you might want to add a log showing the value of server-stop inside the http component
Note not seeing anything about HttpServer starting, just figwheel server started on port: 2358. Could they be conflicting?
only if they want the same port... unless your system is set up so the http-server never actually gets started
I'm not familiar with component/using and how it differs from component/system-using which I am used to using
In user ns, (defn init ...) sets :http-server to use FigwheelServer
oh, so there you go
it's a different component entirely being run
I wouldn't have thought to look for a user.clj in the project... anyway that's why the server isn't stopping, the figwheel component clearly isn't defined to shut down on its stop method
https://github.com/metasoarous/datsys/blob/dev/dev/dat/sys/dev/figwheel_server.clj