Peter Turcsanyi created NIFI-8429:
-------------------------------------
Summary: DBCPConnectionPool leaks registered drivers
Key: NIFI-8429
URL: https://issues.apache.org/jira/browse/NIFI-8429
Project: Apache NiFi
Issue Type: Bug
Components: Extensions
Reporter: Peter Turcsanyi
{{DBCPConnectionPool}} executes the following steps when it gets enabled:
(https://github.com/apache/nifi/blob/f0611f31da6b643e9ed4bbf2c98faf6c44e29ba6/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java#L473-L502)
- creates a custom class loader
- loads the driver's class via {{Class.forName()}} using the class loader
created in the previous step => the driver will be registered in DriverManager
via the driver's static initialiser (1st registration)
- wraps the driver into {{DriverShim}} and registers it in DriverManager => 2nd
registration
- passes the driver's class name and the class loader to {{commons-dbcp2}}'s
{{BasicDataSource}} which in the end instantiates the driver directly and uses
that instance in effect (not the registered ones)
The registered drivers will never get removed/deregistered from DriverManager
(each OnEnabled leaks 2 instances). Unused drivers can also hold other
resources (like threads in case of Oracle driver
https://support.oracle.com/knowledge/Middleware/1901449_1.html) which can lead
to further leaking.
Suggested solution:
- {{PropertyDescriptor.dynamicallyModifiesClassPath(true)}} could be used
instead of the custom class loader
- {{@RequiresInstanceClassLoading}} could be used to load the driver and the
controller service code in the same class loader (which had been the intended
purpose of {{DriverShim}} originally)
- the registered driver could be passed to {{BasicDataSource}} for usage (no
further instance creation needed)
This way only one driver instance (per controller service) would be registered
and used (until the user changes the driver url on the controller service).
This minimises the number of registered drivers and the resource leaking
mentioned earlier.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)