Fork me on GitHub
#tools-build
<
2022-06-03
>
Mark Wardle10:06:28

Hi all. I have a difficult to reproduce issue with building an uberjar, getting the error, at runtime, “clojure class cannot be cast…” where obviously the class names are the same but one is loaded by DynamicClassLoader. My conclusion was that I was getting a class AOT compiled AND dynamically compiled. I ran build again, and it worked. I was using a single namespace in compile-clj’s ns-compile. I seem to have fixed the issue by either adding the problem namespace explicitly in ns-compile or not using ns-compile at all and letting :topo do it's magic. I've only ever got the class cast error at the REPL previously. I've stupidly deleted the problem release but may be able to reproduce the issue if I recreate the conditions and build a few times. Is there a potential race condition or something similar that might cause that? In the meantime, I'm inclined to not use explicit ns-compile options at all.

Mark Wardle10:06:41

The exception report from running an uberjar is shown at https://github.com/wardle/hermes/issues/40

Alex Miller (Clojure team)13:06:15

If you're explicitly listing namespaces, then you need to list enough that you get “everything” compiled. Certainly there are some scenarios you can get into around protocols.

👍 1
Alex Miller (Clojure team)13:06:43

There is no race condition in compiling - that's single threaded, but your app might load and/or compile in multiple threads which can create different orderings of class loading.

Mark Wardle13:06:13

Ahh of course. That's what must be happening. Heavily multithreaded, one thread must be loading dynamically and one using the precompiled class. What was odd was that one build worked, and one didn't. Hence why I thought something was non-deterministic. Never had that for a jar - only at the REPL. Thank you.

seancorfield16:06:19

@U064X3EF3 Has any additional thought been given to changing the default require to use synchronized-require under the hood (like requiring-resolve does)?

👍 1