-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix ClassCastException
in LMAX Disruptor 3 initialization
#2768
Conversation
During startup with an agent, the resulting object can be in the wrong classloader leading to a ClassCastException. Catching that falls back to the old behaviour which works fine The new behaviour was introduced in 2.23.0 with apache#2112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank You for bringing this problem to our attention.
Instead of ignoring the CCE
, I would rather solve its cause.
While LoaderUtil
might be useful to load classes specified by the user, in this case its usage is not appropriate: we exactly know were the class is and we don't need to look in the TCCL.
Can you replace the LoaderUtil
invocation with a simple Class.forName(...).getConstructor()...
chain of methods?
A test case would be useful, although in this case we can probably just add a comment not to use LoaderUtil
with a link to this issue.
We don't use LoaderUtil. The linked issue is this. The full sequence is pretty convoluted
Because this is a class loading race condition with the JVM classes using the log4j2 logger before the JVM is initialized (agents kick in at premain), this is complex to solve outside of log4j2, whereas this patch is pretty simple |
Did you try replacing return (EventHandler<RingBufferLogEvent>)
Class.forName("org.apache.logging.log4j.core.async.RingBufferLogEventHandler")
.getConstructor()
.newInstance(); This version should also be more GraalVM-friendly and shouldn't cause a |
Again, we're not using LoaderUtil. This is also not in Graal (Graal doesn't yet support agents, and when it does it won't have this kind of issue because it flattens classloading) |
Sorry, I am not referring to the code of your application, but these lines in Log4j Core: Lines 56 to 60 in 2d5f582
I think that line 57 constitutes the problem, since it might load the |
Thanks, I'll test that |
that works, sorry took me a while to get what you were suggesting |
@ppkarwasz, I cannot think of an easy way to test this. The rest LGTM. How shall we proceed? |
ClassCastException
in LMAX Disruptor 3 initialization
We should at least add a code comment "Don't use |
During startup with an agent, the resulting object can be in the wrong classloader leading to a ClassCastException. Catching that falls back to the old behaviour which works fine
The new behaviour was introduced in 2.23.0 with #2112