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

All DB Statement and ResultSet should be closed when no longer needed #2425

Closed
DerEwige opened this issue Sep 20, 2022 · 0 comments · Fixed by #2524
Closed

All DB Statement and ResultSet should be closed when no longer needed #2425

DerEwige opened this issue Sep 20, 2022 · 0 comments · Fixed by #2524

Comments

@DerEwige
Copy link
Contributor

I went through the code and to my surpise you don't close any Statement or ResultSet after use.

Afaik this is bad practice and can lead to degraded DB performance and resource leakes (if combined with bad JDBCD driver)

Simple example from: CompareDb.scala

A close() statement after the while(rs.next()) loop would immediately free up the resources

    val rs1 = conn1.prepareStatement(s"SELECT * FROM $table1").executeQuery()
    val rs2 = conn2.prepareStatement(s"SELECT * FROM $table2").executeQuery()

    var hashes1 = List.empty[ByteVector]
    while (rs1.next()) {
      hashes1 = hash1(rs1) +: hashes1
    }
    rs1.close() 

    var hashes2 = List.empty[ByteVector]
    while (rs2.next()) {
      hashes2 = hash2(rs2) +: hashes2
    }
    rs2.close()
t-bast added a commit that referenced this issue Dec 9, 2022
We weren't correctly closing SQL statements when comparing DBs and
migrating them. All the DB handlers for normal operation (read/write
channels, payments, etc) are already correctly closed after execution.

Fixes #2425
t-bast added a commit that referenced this issue Dec 13, 2022
We weren't correctly closing SQL statements when comparing DBs and
migrating them. All the DB handlers for normal operation (read/write
channels, payments, etc) are already correctly closed after execution.

Fixes #2425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants