clay icon indicating copy to clipboard operation
clay copied to clipboard

tools.build does not exit when requiring the Clay API

Open daslu opened this issue 1 year ago • 4 comments

Reported by jason1903 on Slack: https://clojurians.slack.com/archives/C0BQDEJ8M/p1714087040436159

deps.edn:

{:deps {org.clojure/clojure {:mvn/version "1.12.1"} }
 :aliases {:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
                          slipset/deps-deploy {:mvn/version "0.2.1"}
                          org.scicloj/clay {:mvn/version "2-beta8"}}
                   :ns-default build}}}


build.clj:

(ns build
  (:require
    [scicloj.clay.v2.api :as clay]))

(defn hello
  [_opts]
  (println "hello"))

Then

clojure -T:build hello

never exits.

daslu avatar Apr 26 '24 07:04 daslu

The problem is that Clay starts a portal session to receive its client-side code. That session should be stopped afterwards -- we will fix this in a future version.

For now, here is a workaround:

(defn hello
  [_opts]
  (println "hello")
  (portal.api/close))

(Edit: had a typo in this code earlier, missed the important part.)

daslu avatar Apr 26 '24 07:04 daslu

A possibly way to prevent this would be on Portal side - either add a shutdown hook that stops the server (not 100% sure this works) or get http kit updated so that clients could request the "server-loop" thread org.httpkit.server.HttpServer#serverThread be a daemon thread, which does not prevent JVM from stopping.

holyjak avatar Jul 31 '24 07:07 holyjak

@daslu your suggestion did not work for me - the http-kit server kept running. I had to call (portal.runtime.jvm.launcher/stop).

holyjak avatar Jul 31 '24 07:07 holyjak

Interesting.

Thanks for checking and discovering that.

daslu avatar Jul 31 '24 07:07 daslu