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: close ResultSet before closing Statement - suppresses "JDBC resources leaked" warning with agroal #2247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ivan-gomes
Copy link

@ivan-gomes ivan-gomes commented Sep 21, 2024

Description

Summary of the change:

Close ResultSet before closing Statement. Motivation is to suppress "JDBC resource leaked" warning when used with agroal.

Detailed description:
Agroal, a popular javax.sql.DataSource implementation as used by Quarkus and others, issues a "leak report" before automatically closing tracked ResultSets and Statements. If a Statement is closed before related ResultSets are closed it will trigger a leak report - ref.

ex.

2024-09-21 11:14:47,325 WARN  [io.agr.pool] (executor-thread-1) Datasource '<default>': JDBC resources leaked: 4 ResultSet(s) and 0 Statement(s)

This warning occurs on every query with results and can cause developers concern - ref.

The following is a trace of the "leaked" ResultSet being accounted.

addLeakedResultSets:804, ConnectionWrapper (io.agroal.pool.wrapper)
closeTrackedResultSets:72, StatementWrapper (io.agroal.pool.wrapper)
close:84, StatementWrapper (io.agroal.pool.wrapper)
close:72, PreparedStatementWrapper (io.agroal.pool.wrapper)
setHasNext:96, AbstractQuery$ResultIterator (org.jetbrains.exposed.sql)
next:111, AbstractQuery$ResultIterator (org.jetbrains.exposed.sql)
next:91, AbstractQuery$ResultIterator (org.jetbrains.exposed.sql)
next:170, IterableExKt$mapLazy$1$iterator$2 (org.jetbrains.exposed.sql)
firstOrNull:279, CollectionsKt___CollectionsKt (kotlin.collections)
findById:95, EntityClass (org.jetbrains.exposed.dao)
findById:57, EntityClass (org.jetbrains.exposed.dao)
...

Type of Change

Please mark the relevant options with an "X":

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

suppresses "JDBC resources leaked" warning with agroal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant