-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Force loading of JDBC drivers in runtime classloader #7089
Conversation
…re the datasource is created
Fix looks good to me, my only real question is why the test is in the opentracing module? |
Hello @stuartwdouglas, thank you for the review.
I started off trying to reproduce the original issue which uses the opentracing the JDBC driver URL (which requires the opentracing extension). That way it tests the same code path of the original issue. Plus, I couldn't find any tests in our Quarkus codebase which tests the Having said that, I think I can come up with a test case which reproduces this outside of opentracing. Let me know if you prefer that and I can work on it. |
This was introduced in quarkusio#7089, which was specifically about a bug when using opentracing, which no longer has an extension in core, and even its Quarkiverse extension is no longer maintained: https://github.com/quarkiverse/quarkus-smallrye-opentracing The service loading is also causing problems with quarkusio#41995 So, let's not do it all, assuming tests passes.
This was introduced in quarkusio#7089, which was specifically about a bug when using opentracing, which no longer has an extension in core, and even its Quarkiverse extension is no longer maintained: https://github.com/quarkiverse/quarkus-smallrye-opentracing The service loading is also causing problems with quarkusio#41995 So, let's not do it all, assuming tests passes.
This was introduced in quarkusio#7089, which was specifically about a bug when using opentracing, which no longer has an extension in core, and even its Quarkiverse extension is no longer maintained: https://github.com/quarkiverse/quarkus-smallrye-opentracing The service loading is also causing problems with quarkusio#41995 So, let's not do it all, assuming tests passes.
This was introduced in quarkusio#7089, which was specifically about a bug when using opentracing, which no longer has an extension in core, and even its Quarkiverse extension is no longer maintained: https://github.com/quarkiverse/quarkus-smallrye-opentracing The bug was also specific to Java 8. The service loading is also causing problems with quarkusio#41995 So, let's not do it all, assuming tests passes.
Fixes #7079
The issue noted there is due to the way the
java.sql.DriverManager
deals with access tojava.sql.Driver
instances. Callers of various APIs on theDriverManager
are allowed access toDriver
based on classloader checks.In that linked issue, it so happens that the Postgres driver gets loaded (early) in the augmentation classloader whereas the Tracing driver (the one which needs that underlying Postgres driver) gets loaded (a bit late) in the runtime classloader. As a result, the call from the Tracing driver, at runtime, is not allowed access to the Postgres driver.
The reason why this works in Java 11 is because in Java 11 the
java.sql.DriverManager
loads the drivers lazily[1] unlike in Java 8 where theDriverManager
loads them eagerly[2]. Given the reliance on TCCL, inDriverManager
for loading the drivers, this leads to potentially non-deterministic situation where the driver may or may not be loaded in the correct classloader.To remedy this, the commit in this PR, forces loading of (any available)
Driver
s in the runtime classloader just before the datasource is being produced. This ensures that these drivers are then accessible in the rest of the runtime.The commit also includes a testcase which reproduces the failure and verifies the fix.
[1] https://hg.openjdk.java.net/jdk/jdk/file/3b89be93a7e7/src/java.sql/share/classes/java/sql/DriverManager.java#l570
[2] https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/4db0e91b95c8/src/share/classes/java/sql/DriverManager.java#l100