-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Classpath ordering in container dependent on host filesystem #2733
Comments
Hi @cpopp, This is a known issue: #1871 #1907 It's on our radar and something we really wanted to fix early, but we always had other priority issues. The best is to avoid putting multiple different dependency JARs that happen to contain the same class of different versions on your classpath from the beginning. It is really risky to have the same class of different versions, as you observed in your prod env. So it's ideal to fix your dependencies; you never know when those classes will be loaded in a different order in the future on a different environment. If fixing that is not possible, sometimes you could tell Maven to exclude one JAR like this example. Other workarounds could be to set your own Lastly, please use 2.5.2 instead of 1.6.1.
Thanks for the info. Personally, I've been always curious of the exact behavior (of OpenJDK at least). Closing as a dup of #1871. Please follow up there. |
Reading the other issues they seemed to use alternative ways of running their application and then noticed the issue when attempting to use jib. In this issue the varying classpath orderings both came from jib runs using the exact same image (just on different host systems). While the core fix may be the same, I think considering the portability of a Docker image makes this a bit different. |
@saturnism has suggested that you never should have duplicate classes in your classpath. Use something like https://www.mojohaus.org/extra-enforcer-rules/banDuplicateClasses.html to enforce this on your projects. |
I have lost the confidence. |
@loosebazooka in our case the issue was multiple slf4j logging implementations (log4j and logback) that conflicted and not actually duplicate classes. It dynamically chose the implementation based on which it encountered first, and the application bailed with an error when one was used but worked fine with the other. And yes, of course we should not have both on the classpath and have since fixed it since we encountered this issue messing up a planned deploy to the next environment. |
@saturnism @cpopp we've released Jib 2.7.0 which added a new configuration option (
instead of the default
Expanding the dependency list can be useful in AppCDS too. Note that an expanded dependency list can become very long in practice, and we are not sure if there may be a potential issue due to a long command line ("argument list too long" or "command line is too long"). As with other Jib configurations, this option can also be set through the system property ( |
@saturnism @cpopp Jib 3.1.1 is released, which creates two JVM argument files inside an image. One of them is the Java runtime classpath where all the dependencies are explicitly enumerated, which enables Jib to preseve the depending loading order by using this file for Java 9+. (For Java 8, you have to continue to set For those interested, see here for more details. |
Just a simple questio, was this issue somehow related to |
@andreagalle the issue was set, with Java 8 or below, Jib sets |
Environment:
Description of the issue:
The use of /app/libs/* in the classpath argument for java means that ordering of jars on the classpath is dependent on the host system. We had conflicting jars in our application, but it worked fine on our dev servers, however another set of servers had the jars ordered differently on the classpath and the jar conflict resulted in our application not starting.
Expected behavior:
We expect the containers to be as portable as possible between environments so we hoped the classpath would be ordered identically between environments which would occur if for example the jars were listed explicitly on the classpath rather than as /app/libs/*
Steps to reproduce:
jib-maven-plugin
Configuration:Additional Information:
Classpath wildcard iteration on a Linux host is shown here in the openjdk source: https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/java.base/share/native/libjli/wildcard.c#L209
Which points to the use of readdir (https://www.man7.org/linux/man-pages/man3/readdir.3.html) which indicates:
which is exactly what we ran into when the option for mounting the host filesystem differed.
The text was updated successfully, but these errors were encountered: