Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in CIDER by

In a long running process I want to interrupt the repl.
if you set deps.edn with the following:

:aliases {:dev {:jvm-opts ["-Djdk.attach.allowAttachSelf enabled"
                            "-XX:+PreserveFramePointer"
                            "-XX:+UnlockDiagnosticVMOptions"
                            "-XX:+DebugNonSafepoints"]}}

and then in init.el:

(setq cider-clojure-cli-global-options "-Adev")

you can avoid the following error:

ERROR: Cannot stop thread on JDK21+ without -Djdk.attach.allowAttachSelf 
enabled, see https://nrepl.org/nrepl/installation.html#jvmti.

but the java process still continues

1 Answer

+1 vote
ago by

It should be just "-Djdk.attach.allowAttachSelf", without the word "enabled". See https://nrepl.org/nrepl/installation.html#jvmti.

On the CIDER side, it is preferable to customize cider-clojure-cli-global-aliases instead:
(setq cider-clojure-cli-global-aliases ":dev")

ago by
I tried both just in case that mattered. But the behaviour is the same. You can get back to the REPL but the java process continues.
ago by
Fix the `"-Djdk.attach.allowAttachSelf"` first. Then check with `(System/getProperty "jdk.attach.allowAttachSelf")` in the REPL. It should return an empty string and not nil.
ago by
OK I followed your advice and that did the job, cheers.
It might have worked the very 1st time as well but java takes a few seconds to get the message to shut down, and my initial tests were around 6 seconds. Your answer gave me a bit more confidence that it should work. When I upped the long running process to a minute the java process does go down to ~0.2% and doesn't return the function.
My 2nd day with Clojure. Now I can try to learn actual stuff.
ago by
You've accurately identified the timeout. CIDER (nrepl, in fact) first tries to interrupt the thread in a "legal" way, but if that doesn't succeed, it waits for 5 seconds and then kills the thread forcefully. It is not very "safe", might potentially corrupt memory or screw up locks, that's why it's a last resort, but it is totally fine to do that during development.

Welcome to Clojure! Hope you have fun.
...