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

Only one app starts in same tomca9 container. Others fails. #268

Closed
jlahtinen opened this issue Dec 3, 2024 · 10 comments
Closed

Only one app starts in same tomca9 container. Others fails. #268

jlahtinen opened this issue Dec 3, 2024 · 10 comments
Milestone

Comments

@jlahtinen
Copy link
Contributor

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'int org.jruby.RubyString.cat19(org.jruby.util.ByteList, int)' the class loader 'bootstrap' of the current class, java/lang/Object, and the class loader org.apache.catalina.loader.ParallelWebappClassLoader @53811376 for the method's defining class, org/jruby/RubyString, have different Class objects for the type org/jruby/util/ByteList used in the signature (java.lang.Object is in module java.base of loader 'bootstrap'; org.jruby.RubyString is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @53811376, parent loader java.net.URLClassLoader @22d8cfe0)
at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1070)
at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1098)
... 55 more

We are currently running version master...jlahtinen:jruby-rack:kvp5 that allows to deploy more than 1 rails app to same tomcat9

See #262 also

@kares
Copy link
Member

kares commented Dec 3, 2024

could you include the full exception trace please...
those "... 55 more" lines should reveal whether this is due the MethodHandle CONCAT_WITH_CODERANGE.

@headius
Copy link
Member

headius commented Dec 3, 2024

@kares Good theory. I bet this is a private vs public lookup issue again.

@headius
Copy link
Member

headius commented Dec 3, 2024

have different Class objects for the type org/jruby/util/ByteList

This has to be exist somewhere in the system classpath... it's saying that there's two of them, one from the classloader that loaded java/lang/Object (the boot classloader) and one from the classloader that loaded org/jruby/RubyString (the app classloader).

You may be able to grep for ByteList and find it even in binary files like the boot classpath location for Tomcat.

@headius
Copy link
Member

headius commented Dec 3, 2024

Also I see you are running with the method handle stuff patched out... but it still seems to be getting used, according to this error.

@jlahtinen
Copy link
Contributor Author

Full trace

java.lang.ExceptionInInitializerError
        at org.jruby.rack.ext.RackLibrary.load(RackLibrary.java:53)
        at org.jruby.rack.DefaultRackApplicationFactory.loadJRubyRack(DefaultRackApplicationFactory.java:349)
        at org.jruby.rack.DefaultRackApplicationFactory.initRuntime(DefaultRackApplicationFactory.java:360)
        at org.jruby.rack.DefaultRackApplicationFactory.newRuntime(DefaultRackApplicationFactory.java:344)
        at org.jruby.rack.DefaultRackApplicationFactory$RackApplicationImpl.<init>(DefaultRackApplicationFactory.java:449)
        at org.jruby.rack.DefaultRackApplicationFactory.createApplication(DefaultRackApplicationFactory.java:437)
        at org.jruby.rack.DefaultRackApplicationFactory.newApplication(DefaultRackApplicationFactory.java:102)
        at org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java:117)
        at org.jruby.rack.SharedRackApplicationFactory.doInit(SharedRackApplicationFactory.java:36)
        at org.jruby.rack.RackApplicationFactoryDecorator.init(RackApplicationFactoryDecorator.java:104)
        at org.jruby.rack.RackServletContextListener.contextInitialized(RackServletContextListener.java:50)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4018)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4460)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:599)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:571)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:603)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1014)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1866)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:816)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1584)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:312)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:109)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:389)
        at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:336)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:776)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:721)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1203)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1193)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:749)
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:211)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:415)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:874)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:164)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:735)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
Caused by: java.lang.IllegalAccessException: no such method: org.jruby.RubyString.cat19(ByteList,int)int/invokeVirtual
        at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:959)
        at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1101)
        at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030)
        at java.base/java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:1194)
        at org.jruby.rack.ext.Input.<clinit>(Input.java:57)
        ... 52 more

@jlahtinen
Copy link
Contributor Author

Also I see you are running with the method handle stuff patched out... but it still seems to be getting used, according to this error.

In this case I am running without any custom patches. This should be identical to version #262 merged to master.

@jlahtinen
Copy link
Contributor Author

jlahtinen commented Dec 4, 2024

Nokogiri brings xercesImpl-2.12.2.jar with it.

It is the only that contains another ByteList I can find.

grep: org/apache/xerces/impl/dv/util/ByteListImpl.class: binary file matches
grep: org/apache/xerces/impl/dv/xs/Base64BinaryDV$XBase64.class: binary file matches
grep: org/apache/xerces/impl/dv/xs/HexBinaryDV$XHex.class: binary file matches
grep: org/apache/xerces/xs/datatypes/ByteList.class: binary file matches

I removed that jar from apps but #268 (comment) keeps coming.

@headius
Copy link
Member

headius commented Dec 4, 2024

@jlahtinen Yeah I wouldn't expect that ByteList to conflict.

Two patches for you to try (first one would be best, try second if that fails):

Patch 1: non-public MH lookup

diff --git a/src/main/java/org/jruby/rack/ext/Input.java b/src/main/java/org/jruby/rack/ext/Input.java
index 2cdd8e3..ddd1e1b 100644
--- a/src/main/java/org/jruby/rack/ext/Input.java
+++ b/src/main/java/org/jruby/rack/ext/Input.java
@@ -49,7 +49,7 @@ public class Input extends RubyObject {
         // set up coderange-aware concat that works with the new catWithCodeRange as well as earlier JRuby without it.
         // TODO: remove and replace with direct call once 9.3 is fully unsupported
         MethodHandle catWithCR = null;
-        MethodHandles.Lookup lookup = MethodHandles.publicLookup();
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
         try {
             catWithCR = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(int.class, ByteList.class, int.class));
         } catch (NoSuchMethodException | IllegalAccessException e) {

Patch 2: reflection and unreflect

diff --git a/src/main/java/org/jruby/rack/ext/Input.java b/src/main/java/org/jruby/rack/ext/Input.java
index 2cdd8e3..0028d67 100644
--- a/src/main/java/org/jruby/rack/ext/Input.java
+++ b/src/main/java/org/jruby/rack/ext/Input.java
@@ -51,10 +51,10 @@ public class Input extends RubyObject {
         MethodHandle catWithCR = null;
         MethodHandles.Lookup lookup = MethodHandles.publicLookup();
         try {
-            catWithCR = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(int.class, ByteList.class, int.class));
+            catWithCR = lookup.unreflect(RubyString.class.getMethod("catWithCodeRange", ByteList.class, int.class));
         } catch (NoSuchMethodException | IllegalAccessException e) {
             try {
-                catWithCR = lookup.findVirtual(RubyString.class, "cat19", MethodType.methodType(int.class, ByteList.class, int.class));
+                catWithCR = lookup.unreflect(RubyString.class.getMethod("cat19", ByteList.class, int.class));
             } catch (Exception t) {
                 Helpers.throwException(t);
             }

@jlahtinen
Copy link
Contributor Author

@headius patch 1 worked

@headius
Copy link
Member

headius commented Dec 4, 2024

@jlahtinen Figures! I'll merge that in.

@headius headius closed this as completed in b813106 Dec 4, 2024
@headius headius added this to the 1.2.3 milestone Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants