Fork me on GitHub
#clerk
<
2023-06-20
>
jkrasnay01:06:38

Hi all, I just cloned clerk-demo, started it per the instructions in the README, and I’m getting an error screen. Any ideas on what’s going wrong?

hiredman01:06:18

That error indicates clojures agent send-off/future threadpool has been shutdown

hiredman01:06:51

Typically as a result of calling shutdown-agents

mkvlr12:06:40

hey @jkrasnay, I can reproduce the issue, taking a look

mkvlr13:06:18

I’m pretty confused as to why this is happening (and why I hadn’t seen this before). https://github.com/nextjournal/clerk/blob/4f41d6782ee453970e13a03b8257e6134820c33c/src/nextjournal/clerk/webserver.clj#L257 where the exception occurs. It works if I comment out the future call. It also fails with an empty (future) call. Anyone else have an idea on things I could try?

mkvlr13:06:29

can also repro it with just the clerk repo and it seems to be related to running with -M: this fails:

mk@mkstudio ~/d/clerk (main)> clj -M:nextjournal/clerk nextjournal.clerk/serve! --browse
Clerk webserver started on  ...
this works:
mk@mkstudio ~/d/clerk (main)> clj -X:nextjournal/clerk nextjournal.clerk/serve! :browse true
Clerk webserver started on  ...
Clerk evaluated 'file:/Users/mk/dev/clerk/src/nextjournal/clerk/home.clj' in 2144.897625ms.

mkvlr13:06:52

@jkrasnay you can use clj -X:nextjournal/clerk nextjournal.clerk/serve! :watch-paths '["notebooks"]' :port 7777 :browse true as an alternative startup command that works until we figure out why the -M invocation from the readme is broken.

mkvlr13:06:36

@borkdude do you maybe have an idea? We get this error regarding agents when we start via -M (and babashka cli) but it works with -X.

mkvlr13:06:10

can try this on both clerk and clerk-demo repos

borkdude13:06:41

@U5H74UNSF So just run clj -M:nextjournal/clerk nextjournal.clerk/serve! --browse on clerk and then I should see an error?

mkvlr13:06:36

@borkdude yes, correct. Just verified it once more here that I do see the error

borkdude13:06:25

What I'm seeing is:

clj -M:nextjournal/clerk nextjournal.clerk/serve! --browse
Clerk webserver started on  ...

mkvlr13:06:43

yes, the error should be in the browser that opens

mkvlr13:06:50

> Unhandled java.util.concurrent.RejectedExecutionException > Task java.util.concurrent.FutureTask@78d3d660[Not completed, task = clojure.core$binding_conveyor_fn$fn__5823@6a9a4b8c] rejected from java.util.concurrent.ThreadPoolExecutor@2f6867d1[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

borkdude13:06:59

I just get a blank screen

mkvlr13:06:08

any local changes?

borkdude13:06:20

not to clerk itself

mkvlr13:06:27

to the deps.edn?

borkdude13:06:32

storage.clerk.garden/nextjournal/clerk-assets@3Y9hSHm7RtAcnVHB3dfLn3raLZM1/viewer.js?immutable=true:1     Failed to load resource: the server responded with a status of 404 ()
'nextjournal.clerk.home:425 Uncaught ReferenceError: nextjournal is not defined
    at 'nextjournal.clerk.home:425:609

borkdude13:06:38

I'll try from main

mkvlr13:06:48

yeah blank screen is if the js isn’t loading

mkvlr13:06:18

because of a different hash (can happen with local modifications to the deps.edn)

borkdude13:06:13

I'll make a PR

mkvlr13:06:53

found it already?

borkdude13:06:15

It's expected behavior, just wait for PR

🆗 2
borkdude13:06:03

maybe I'm misunderstanding btw. if you --browse, what is the normal behavior, should the JVM exit?

mkvlr13:06:10

should not exit

mkvlr13:06:14

think we should barf the form out

mkvlr13:06:38

the form you added, so it also doens’t exit when you don’t pass browse

borkdude14:06:19

so this CLI never has to exit

mkvlr14:06:45

serve! starts a server, so no

mkvlr14:06:01

build! should exit when it’s done

borkdude14:06:06

ok. I think if you would install clerk as a -T it would probably give the same problem

borkdude14:06:14

but -X doesn't shutdown agents, -T does

borkdude14:06:51

so we should probably always wait, instead of exit, regardless of bb.cli

mkvlr14:06:28

if we call it interactively, we don’t want to wait

borkdude14:06:32

pushed the improvement

borkdude14:06:04

right, this is the shit with CLI functions, you can't always re-use them as composable functions

borkdude14:06:16

so maybe split it into two separate functions then

borkdude14:06:54

or add an extra parameter --wait false or so

mkvlr14:06:46

so if we check for the bb.cli case we would have a problem with -T

mkvlr14:06:06

not sure if anyones using clerk as a tool, what would be the use case?

mkvlr14:06:02

did anything change recently regarding this? Wondering why we never ran into it until now

borkdude14:06:43

I'd expect so, but I'm trying:

clj -T nextjournal.clerk/serve! :browse true
and it doesn't exit

borkdude14:06:20

I'll check into the -T implementation

🙏 2
mkvlr14:06:44

the other thing also didn’t exit, maybe because it starts daemon threads in the meantime?

borkdude14:06:53

aha:

* **1.10.3.933 on July 28, 2021**
  * **TDEPS-198 - on -X, don't use System/exit or shutdown-agents (but don't let agent threads block exit)**
* 1.10.3.929 on July 21, 2021
* 1.10.3.912 on July 15, 2021
  * On -X success, exit with (shutdown-agents) instead of System/exit

borkdude14:06:10

I guess I'll have to change this in babashka.cli as well then

borkdude14:06:47

So:

On startup: make future/agent threadpool into non-daemon threads

mkvlr14:06:03

this is in babashka.cli?

borkdude14:06:24

no, this is the chosen direction of TDEPS-198

borkdude14:06:37

which I'm now trying to implement. But using a local/root dep changes the deps.edn so I can't just launch it

mkvlr14:06:06

yes, need to set "-Dclerk.resource_manifest={\"/js/viewer.js\" \"/js/viewer.js\"}"

mkvlr14:06:18

grabbing the value, one sec

mkvlr14:06:10

so with "-Dclerk.resource_manifest={\"/js/viewer.js\" \"\"}" it should work

borkdude14:06:31

seems to work :-D

mkvlr14:06:38

huh, so with this I can then bump cli instead of making a change to clerk?

borkdude14:06:34

yes, after I publish a new version of cli

mkvlr14:06:46

excellent, thank you!

borkdude15:06:04

Updated https://github.com/nextjournal/clerk/pull/520: the only change is upgrading babashka.cli

💯 4
mkvlr15:06:20

thank you, merged!

🎉 4
jkrasnay16:06:47

Works. Thanks for the quick fix!

🙌 2
mkvlr16:06:32

thanks for reporting the bug!

jkrasnay01:06:59

~/ws/clerk-demo [main]
λ java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Temurin-11.0.15+10 (build 11.0.15+10)
OpenJDK 64-Bit Server VM Temurin-11.0.15+10 (build 11.0.15+10, mixed mode)
~/ws/clerk-demo [main]
λ clojure -version
Clojure CLI version 1.11.1.1273

jkrasnay12:06:04

It seems to have been broken by b49d404. Works if I back up to abc5922.

mkvlr13:06:18

I’m pretty confused as to why this is happening (and why I hadn’t seen this before). https://github.com/nextjournal/clerk/blob/4f41d6782ee453970e13a03b8257e6134820c33c/src/nextjournal/clerk/webserver.clj#L257 where the exception occurs. It works if I comment out the future call. It also fails with an empty (future) call. Anyone else have an idea on things I could try?

mkvlr13:06:52

@jkrasnay you can use clj -X:nextjournal/clerk nextjournal.clerk/serve! :watch-paths '["notebooks"]' :port 7777 :browse true as an alternative startup command that works until we figure out why the -M invocation from the readme is broken.