Fork me on GitHub
#cider
<
2018-07-16
>
bozhidar08:07:43

Does anyone know how to keep a lein process running after it spawned some server?

bozhidar08:07:06

I’m trying to create a simple lein plugin to just run the new nREPL server, but I hit a surprising roadblock - the server starts and then lein just exits and kills it.

bozhidar08:07:09

(defn nrepl
  "Start a headless nREPL server within your project's context."
  [project & args]
  (println args)
  (eval/eval-in-project
   project
   `(start-nrepl ~(convert-args args))))

bozhidar08:07:00

(this just uses the start-nrepl wrapper from cider-nrepl and passes it a hash with the params it normally expects.

bozhidar08:07:45

I took a look at https://github.com/technomancy/leiningen/blob/master/src/leiningen/repl.clj and I don’t quite understand everything it does to spin the headless server. I really don’t want to copy all of this, as it seems more complex than it needs to be.

dominicm08:07:09

I would expect it's to do with thread daemonization...

bozhidar08:07:38

@dominicm Are you referring to this?

bozhidar08:07:41

(defn server [project cfg headless?]
  (nrepl.ack/reset-ack-port!)
  (when-not (nrepl-dependency? project)
    (main/info "Warning: no nREPL dependency detected.")
    (main/info "Be sure to include org.clojure/tools.nrepl in :dependencies"
               "of your profile."))
  (let [prep-blocker @eval/prep-blocker
        ack-port (:port @ack-server)]
    (-> (bound-fn []
          (binding [eval/*pump-in* false]
            (let [[evals requires]
                  (server-forms project cfg ack-port headless?)]
              (eval/eval-in-project project
                                    `(do ~(ignore-sigint-form) ~evals)
                                    requires))))
        (Thread.) (.start))
    (when project @prep-blocker)
    (when headless? @(promise))
    (if-let [repl-port (nrepl.ack/wait-for-ack
                        (get-in project [:repl-options :timeout] 60000))]
      (do (main/info "nREPL server started on port"
                     repl-port "on host" (:host cfg)
                     (str "- nrepl://" (:host cfg) ":" repl-port))
          repl-port)
      (main/abort "REPL server launch timed out."))))

dominicm08:07:21

I just meant general JVM thread daemonization.

dominicm08:07:36

Looks like they're working around the problem by blocking via @(promise)

bozhidar09:07:39

Yeah, I was just wondering if there’s isn’t some higher-level logic in Lein to deal with daemons.

bozhidar09:07:24

Anyways, blocking the functions that starts the process works like charm. Should have thought of this earlier. I’ll share in a bit the new “fancy” plugin. 😄

dominicm16:07:44

Anyone around with an emacs nrepl connected who can confirm the behaviour in the case of two requires? https://github.com/clojure-vim/clj-refactor.nvim/issues/30 Only if it's really convenient and you aren't put off by vim users using the information.

justinbarclay17:07:23

I can confirm this behaviour. Given multiple require statements only the first one remains and any subsequent require is dropped/goes missing.

dominicm05:07:57

Interesting, thanks!

bozhidar20:07:37

I’ve started hacking on the migration to nREPL 0.4 today - I’d love to see some people play with https://github.com/clojure-emacs/cider-nrepl/pull/540

jlfischer20:07:51

Quick question: I'm starting my nREPL sessions manually (using the instructions here: https://github.com/clojure-emacs/cider-nrepl#via-embedding-nrepl-in-your-app), and connecting via cider-connect-clj, but any attempts to execute code in the repl (e.g. (println "Hi"), load files, evaluate anything, either hang or after some chunk of time give me an nREPL sync error. Any suggestions where to look to get it working?

jlfischer20:07:05

Cider reports this after connecting:

;; Connected to nREPL server - 
;; CIDER 0.18.0snapshot (package: 20180714.811), nREPL 0.2.13
;; Clojure 1.9.0, Java 1.8.0_144

jlfischer20:07:12

FWIW, I don't end up with an *nrepl-messages* buffer, so I don't have a good view into what's going on.

jlfischer20:07:06

Scratch that, enabled nrepl logging according to http://docs.cider.mx/en/latest/troubleshooting/#missing-nrepl-messages-buffer and I've got the buffer. But still, it's just hanging trying to eval something simple:

(-->
  id           "9"
  op           "eval"
  session      "ebe59b11-8cb8-484f-b75f-7444556b4a6b"
  time-stamp   "2018-07-16 13:52:46.713737000"
  code         "(println \"Hi\")"
  column       7
  content-type "true"
  file         "*cider-repl localhost(clj)*"
  line         43
  ns           "user"
)