luminus-template icon indicating copy to clipboard operation
luminus-template copied to clipboard

(stop) fails on fresh 'lein new luminus prj +http-kit'

Open Ramblurr opened this issue 5 years ago • 2 comments

To reproduce

$ lein new luminus lumtest +http-kit
$ cd lumtest
$ lein repl
user=> (start)
user=> (stop)

Results

user=> (start)
2020-08-12 08:52:21,558 [nREPL-session-a1fbf890-d24b-4206-a536-cce6f5197ae8] INFO  lumtest.env - 
-=[lumtest started successfully using the development profile]=- 
2020-08-12 08:52:21,832 [nREPL-session-a1fbf890-d24b-4206-a536-cce6f5197ae8] INFO  luminus.http-server - starting HTTP server on port 3000 
{:started ["#'lumtest.config/env" "#'lumtest.handler/init-app" "#'lumtest.handler/app-routes" "#'lumtest.core/http-server"]}
user=> (stop)
#error {
 :cause "class clojure.lang.AFunction$1 cannot be cast to class java.util.concurrent.Future (clojure.lang.AFunction$1 is in unnamed module of loader 'app'; java.util.concurrent.Future is in module java.base of loader 'bootstrap')"
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "could not stop [#'lumtest.core/http-server] due to"
   :data {}
   :at [mount.core$down$fn__446 invoke "core.cljc" 96]}
  {:type java.lang.ClassCastException
   :message "class clojure.lang.AFunction$1 cannot be cast to class java.util.concurrent.Future (clojure.lang.AFunction$1 is in unnamed module of loader 'app'; java.util.concurrent.Future is in module java.base of loader 'bootstrap')"
   :at [clojure.core$deref_future invokeStatic "core.clj" 2298]}]
 :trace
 [[clojure.core$deref_future invokeStatic "core.clj" 2298]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [luminus.http_server$stop invokeStatic "http_server.clj" 16]
  [luminus.http_server$stop invoke "http_server.clj" 15]
  [lumtest.core$eval12850$fn__12856 invoke "core.clj" 31]
  [mount.core$record_BANG_ invokeStatic "core.cljc" 74]
  [mount.core$record_BANG_ invoke "core.cljc" 73]
  [mount.core$down$fn__446 invoke "core.cljc" 97]
  [mount.core$down invokeStatic "core.cljc" 96]
  [mount.core$down invoke "core.cljc" 86]
  [mount.core$bring invokeStatic "core.cljc" 247]
  [mount.core$bring invoke "core.cljc" 239]
  [mount.core$stop invokeStatic "core.cljc" 300]
  [mount.core$stop doInvoke "core.cljc" 291]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 665]
  [clojure.core$apply invoke "core.clj" 660]
  [mount.core$stop_except invokeStatic "core.cljc" 382]
  [mount.core$stop_except doInvoke "core.cljc" 377]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [user$stop invokeStatic "user.clj" 24]
  [user$stop invoke "user.clj" 21]
  [user$eval13396 invokeStatic "form-init9286139410565183375.clj" 1]
  [user$eval13396 invoke "form-init9286139410565183375.clj" 1]
  [clojure.lang.Compiler eval "Compiler.java" 7177]
  [clojure.lang.Compiler eval "Compiler.java" 7132]
  [clojure.core$eval invokeStatic "core.clj" 3214]
  [clojure.core$eval invoke "core.clj" 3210]
  [nrepl.middleware.interruptible_eval$evaluate$fn__11892 invoke "interruptible_eval.clj" 91]
  [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437]
  [clojure.main$repl$fn__9095 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl doInvoke "main.clj" 368]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 84]
  [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 56]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__11918$fn__11922 invoke "interruptible_eval.clj" 155]
  [clojure.lang.AFn run "AFn.java" 22]
  [nrepl.middleware.session$session_exec$main_loop__12019$fn__12023 invoke "session.clj" 190]
  [nrepl.middleware.session$session_exec$main_loop__12019 invoke "session.clj" 189]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 834]]}
2020-08-12 08:52:33,463 [nREPL-session-a1fbf890-d24b-4206-a536-cce6f5197ae8] INFO  lumtest.env - 
-=[lumtest has shut down successfully]=- 
{:stopped ["#'lumtest.handler/init-app"]}

Subsequent (start)s fail!

Ramblurr avatar Aug 12 '20 06:08 Ramblurr

This seems to be related to this recent change in https://github.com/http-kit/http-kit/commit/6564580af698ec067523177796206a77b7cd0d9b

Here is a workaround:

(mount/defstate ^{:on-reload :noop} http-server
  :start
  (http/start
    (-> env
        (assoc :handler (handler/app))
        (assoc :legacy-return-value? false)  ;; <--- added
        (update :port #(or (-> env :options :port) %))))
  :stop
  @(future (httpkit/server-stop! http-server {:timeout 100})))  ;; <--- changed

Ramblurr avatar Aug 12 '20 11:08 Ramblurr

Thanks for the heads up, I ended up putting the fix in luminus-http-kit, so you should be able to just switch the dependency to [luminus-http-kit "0.1.8"] now.

yogthos avatar Aug 12 '20 14:08 yogthos