Skip to content
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

Fix Statement leak in Trino JDBC DatabaseMetaData #10632

Merged
merged 5 commits into from
Jan 18, 2022

Conversation

findepi
Copy link
Member

@findepi findepi commented Jan 15, 2022

Before the change, Trino JDBC's DatabaseMetaData implementation
(TrinoDatabaseMetaData) would create Statement objects that are
never closed. Since Connection (TrinoConnection) tracks open
statements to be able to close them upon Connection.close() (per JDBC
requirements), this created a memory leak where Statement objects are
leaked in Connection.statements collection.

The commit fixing this, under the condition that ResultSet returned
from TrinoDatabaseMetaData is correctly closed.

Fixes #10584

@cla-bot cla-bot bot added the cla-signed label Jan 15, 2022
@findepi findepi added the jdbc Relates to Trino JDBC driver label Jan 15, 2022
Copy link
Member

@electrum electrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is better than my first idea of a weak reference

`AsyncIterator.cancel` is idempotent (future cancellation) and
`client.close()` is idempotent too (state atomic swap controls that), so
this is not a behavioral change, but necessary for further code
evolution.
It's somewhat more readable if the mutable state, especially one that
needs to be updated with thread-safety in mind, is confined to a class.
Before the change, Trino JDBC's `DatabaseMetaData` implementation
(`TrinoDatabaseMetaData`) would create `Statement` objects that are
never closed. Since `Connection` (`TrinoConnection`) tracks open
statements to be able to close them upon `Connection.close()` (per JDBC
requirements), this created a memory leak where `Statement` objects are
leaked in `Connection.statements` collection.

The commit fixing this, under the condition that `ResultSet` returned
from `TrinoDatabaseMetaData` is correctly closed.
@findepi
Copy link
Member Author

findepi commented Jan 18, 2022

CI #10631 (comment)

@findepi findepi merged commit 96287a6 into trinodb:master Jan 18, 2022
@findepi findepi deleted the findepi/jdbc-statement-leak branch January 18, 2022 08:15
@github-actions github-actions bot added this to the 369 milestone Jan 18, 2022
@findepi findepi mentioned this pull request Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed jdbc Relates to Trino JDBC driver
Development

Successfully merging this pull request may close these issues.

Memory leak in Trino JDBC driver when using DatabaseMetaData
4 participants