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

DB pool behaves incorrectly when I close the same connection multiple times #80

Open
cbxp opened this issue Sep 24, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@cbxp
Copy link
Collaborator

cbxp commented Sep 24, 2024

Case:

I close DB connection multiple times

Expected result:

it's totally fine. The first close() call closes the connection, and the following close() calls are just ignored.

Actual result:

  1. The connection is added to pool.available multiple times.
  2. As a result, subsequent calls to pool.getConnection() return the same connection multiple times.

Failing test:

class PooledDataSourceTest {

  @Test fun `close same connection multiple times`() {
    val conn = pool.connection
    expect(pool.used.keys).toHaveSize(1)
    expect(pool.available).toHaveSize(0)

    conn.close()
    conn.close()
    conn.close()

    expect(pool.used.keys).toHaveSize(0)
    expect(pool.available).toHaveSize(1)  // Fails: pool.available.size is 3

    val conn2 = pool.connection
    expect(pool.connection).notToEqual(conn2) // Fails: it's the same connection
    expect(pool.connection).notToEqual(conn2)
  }
}
@cbxp cbxp added the bug Something isn't working label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant