bobpaulin commented on code in PR #10670:
URL: https://github.com/apache/nifi/pull/10670#discussion_r2636616411
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java:
##########
@@ -261,9 +265,13 @@ protected Driver getDriver(final String driverName, final
String url) {
return DriverManager.getDriver(url);
} catch (final SQLException e) {
// In case the driver is not registered by the implementation, we
explicitly try to register it.
+ // deregister existing driver
try {
- final Driver driver = (Driver)
clazz.getDeclaredConstructor().newInstance();
- DriverManager.registerDriver(driver);
+ if (registeredDriver != null) {
+ DriverManager.deregisterDriver(registeredDriver);
+ }
+ registeredDriver = (Driver)
clazz.getDeclaredConstructor().newInstance();
Review Comment:
Hi I am testing with postgres jdbc which does have the services meta data
https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/resources/META-INF/services/java.sql.Driver
The problem is not the driver loading. It's the reference escaping into
the System Classloader through the DriverManager.register function. This code
addresses that by deregistering the ones that get there. I've tested it by
loading, enabling and removing the component programmatically a couple hundred
times.
Without the code
<img width="480" height="386" alt="image"
src="https://github.com/user-attachments/assets/9a25472b-2942-4a6a-9fba-9f9c43c1925d"
/>
With
<img width="720" height="649" alt="image"
src="https://github.com/user-attachments/assets/2616ea78-27d0-40ae-91a1-2ef77e25df7c"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]