Bug 65845 - The "DelegatingConnection.getCatalog" method can return incorrect cached values
Summary: The "DelegatingConnection.getCatalog" method can return incorrect cached values
Status: RESOLVED MOVED
Alias: None
Product: Tomcat 10
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal (vote)
Target Milestone: ------
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-25 16:10 UTC by ismaeltf
Modified: 2022-01-25 17:10 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ismaeltf 2022-01-25 16:10:47 UTC
Starting with Tomcat 9.0.53 (Update the internal fork of Apache Commons DBCP to 2.9.0 (2021-08-03). Improvements, code clean-up and refactoring.), Commons DBCP started caching the catalog name returned by "getCatalog" (https://github.com/apache/tomcat/blame/9.0.53/java/org/apache/tomcat/dbcp/dbcp2/DelegatingConnection.java). This can cause the method to return incorrect values after using a pooled connection to execute a SQL command that effectively changes the catalog of the connection.

The motivation for executing a SQL command that changes the catalog of a connection instead of calling "setCatalog" is that some vendors provide commands that allow for "new connections" to happen on an already established connection (i.e. commands that allow connecting to a different catalog, with a different user). Commons DBCP doesn't offer a way to clear the cache of a connection when something like this happens, which can lead to incorrect results.

We also think that calling the "close" method on the connection should invoke the "clearCachedState" method (as it is called when a transaction ends: https://github.com/apache/commons-dbcp/blob/922eb2685ff64bdb27607ceecbe333330e5be4c0/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java).
Comment 1 Mark Thomas 2022-01-25 16:56:05 UTC
You'll need to raise this with the DBCP 2 project:
https://issues.apache.org/jira/projects/DBCP/issues
Comment 2 ismaeltf 2022-01-25 17:10:58 UTC
We have opened https://issues.apache.org/jira/browse/DBCP-583. Thanks!