Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsscripting] Dropping/Updating JAR bundle causes UnsatisfiedLinkError: Native library already loaded in another classloader #18054

Open
florian-h05 opened this issue Jan 6, 2025 · 4 comments
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@florian-h05
Copy link
Contributor

Updating the JS Scripting JAR bundle in the addons folder causes the following exception:

14:21:28.248 [ERROR] [nal.provider.ScriptModuleTypeProvider] - bundle org.openhab.core.automation.module.script:5.0.0.202501050301 (165)[org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider(103)] : The setScriptEngineFactory method has thrown an exception
java.lang.NoClassDefFoundError: Could not initialize class org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine
        at org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory.createScriptEngine(GraalJSScriptEngineFactory.java:90) ~[?:?]
        at org.openhab.core.automation.module.script.internal.ScriptEngineFactoryHelper.getParameterOption(ScriptEngineFactoryHelper.java:45) ~[?:?]
        at org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider.setScriptEngineFactory(ScriptModuleTypeProvider.java:150) ~[?:?]
        at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
        ...
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.InternalError: java.lang.UnsatisfiedLinkError: Native Library /root/.cache/org.graalvm.polyglot/engine/libtruffleattach/855be25834bb645ea86aa0d0e83e8f1d55c8d56bb5e7858a90f48bfcf638e541/bin/libtruffleattach.so already loaded in another classloader [in thread "Automation Provider Processing Queue"]
        at com.oracle.truffle.runtime.ModulesSupport.loadModulesSupportLibrary(ModulesSupport.java:170) ~[bundleFile:?]
        at com.oracle.truffle.runtime.ModulesSupport.<clinit>(ModulesSupport.java:59) ~[bundleFile:?]
        at com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntimeAccess.createRuntime(HotSpotTruffleRuntimeAccess.java:84) ~[bundleFile:?]
        at com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntimeAccess.getRuntime(HotSpotTruffleRuntimeAccess.java:75) ~[bundleFile:?]
        at com.oracle.truffle.api.Truffle.createRuntime(Truffle.java:145) ~[bundleFile:?]
        at com.oracle.truffle.api.Truffle$1.run(Truffle.java:176) ~[bundleFile:?]
        at com.oracle.truffle.api.Truffle$1.run(Truffle.java:174) ~[bundleFile:?]

I thought this could be solved by OSGi-ifying the Graal dependencies, so that only one bundle loading that native library is active.
This will also be required or at least nice to have when having a GraalPython add-on.

For this, I created openhab/openhab-osgiify#57.
Unfortunately, I am not able to OSGI-ify truffle-api and truffle-runtime (see the linked PR) due to unresolved requirements, that seem like circular dependencies.

Next, I have created #18053 to try make use of the OSGi-ified GraalVM Polyglot dependency, but this fails with:

14:47:56.384 [ERROR] [nal.provider.ScriptModuleTypeProvider] - bundle org.openhab.core.automation.module.script:5.0.0.202501050301 (165)[org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider(188)] : The setScriptEngineFactory method has thrown an exception
java.lang.NoClassDefFoundError: Could not initialize class org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine
        at org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory.createScriptEngine(GraalJSScriptEngineFactory.java:90) ~[?:?]
        at org.openhab.core.automation.module.script.internal.ScriptEngineFactoryHelper.getParameterOption(ScriptEngineFactoryHelper.java:45) ~[?:?]
        at org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider.setScriptEngineFactory(ScriptModuleTypeProvider.java:150) ~[?:?]
        at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
        ...
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.IllegalStateException: No language and polyglot implementation was found on the module-path. Make sure at last one language is added to the module-path.  [in thread "fileinstall-/usr/share/openhab/addons"]
        at org.graalvm.polyglot.Engine$PolyglotInvalid.noPolyglotImplementationFound(Engine.java:1801) ~[?:?]
        at org.graalvm.polyglot.Engine$PolyglotInvalid.buildSource(Engine.java:1888) ~[?:?]
        at org.graalvm.polyglot.Engine$PolyglotInvalid.buildSource(Engine.java:1754) ~[?:?]
        at org.graalvm.polyglot.Source$Builder.build(Source.java:1027) ~[?:?]
@florian-h05 florian-h05 added the bug An unexpected problem or unintended behavior of an add-on label Jan 6, 2025
@jlaur
Copy link
Contributor

jlaur commented Jan 6, 2025

@florian-h05 - FWIW, I've seen this exception too recently with the 5.0 snapshot versions. I'm not using a JAR.

@florian-h05
Copy link
Contributor Author

I think it occurs when installing some add-ons and some bundles are reloaded due to this.
Fortunately habe restart times decreases much with openHAB 5 in my experience.

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-0-snapshot-discussion/161404/3

@florian-h05
Copy link
Contributor Author

@wborn May I ask for your help here? I think this needs an OSGi expert …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

No branches or pull requests

3 participants