magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Boot and Optimus (clj-v8) cause `java.lang.UnsatisfiedLinkError` #47

Open domkm opened 8 years ago

domkm commented 8 years ago

When using Optimus with Boot, I get this error:

clojure.lang.Compiler$CompilerException: java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/t2/kbjbdrwd5dzf_hh9gjfnz_b00000gn/T/libv8.dylib.clj-v8 already loaded in another classloader, compiling:(v8/core.clj:36:1)
         java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/t2/kbjbdrwd5dzf_hh9gjfnz_b00000gn/T/libv8.dylib.clj-v8 already loaded in another classloader

How close are we to moving from clj-v8 to Nashorn? Is this fixable before the move?

/CC @micha @alandipert @pbiggar

magnars commented 8 years ago

I know @arbscht has been trying to get a patch into clj-v8 so we can do a smooth transition to Nashorn, instead of breaking compatibility with older Java versions, but it's been quiet on that front for a while. See #14.

radhikalism commented 8 years ago

Work on moving to Nashorn via JSR-223 is in progress again at #14.

Meanwhile, I'd like to see if this can be fixed in the short-term too. Can you provide steps to reproduce the error? (I'm not familiar enough with Boot just yet.)

domkm commented 8 years ago

Sure thing, @arbscht.

  1. Install Boot
  2. Run boot -d optimus repl
  3. Run (require 'optimus.optimizations.minify)
  4. Run (require 'optimus.optimizations.minify :reload-all)
↪ boot -d optimus repl
nREPL server started on port 53974 on host 127.0.0.1 - nrepl://127.0.0.1:53974
REPL-y 0.3.5, nREPL 0.2.8
Clojure 1.7.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_20-b26
        Exit: Control+D or (exit) or (quit)
    Commands: (user/help)
        Docs: (doc function-name-here)
              (find-doc "part-of-name-here")
Find by Name: (find-name "part-of-name-here")
      Source: (source function-name-here)
     Javadoc: (javadoc java-object-or-class-here)
    Examples from clojuredocs.org: [clojuredocs or cdoc]
              (user/clojuredocs name-here)
              (user/clojuredocs "ns-here" "name-here")
boot.user=> (require 'optimus.optimizations.minify)
nil
boot.user=> (require 'optimus.optimizations.minify :reload-all)
clojure.lang.Compiler$CompilerException: java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/t2/kbjbdrwd5dzf_hh9gjfnz_b00000gn/T/libv8.dylib.clj-v8 already loaded in another classloader, compiling:(v8/core.clj:36:1)
         java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/t2/kbjbdrwd5dzf_hh9gjfnz_b00000gn/T/libv8.dylib.clj-v8 already loaded in another classloader
radhikalism commented 8 years ago

@DomKM, this looks like a bug in clj-v8. I've proposed a PR at circleci/clj-v8#15. If you can install from source, see if that works for you.

The underlying problem seems to be that native libraries must not be loaded twice in a JVM, but clj-v8 happens to eagerly (re-)load its native objects.

Now, I don't know which is more likely to land first: a new clj-v8 release or a Nashorn-capable Optimus… :smile:

karneaud commented 8 years ago

+1 has a fixed been applied?