Skip to content

[core] Fix JDBC connection leak in ClientPool and JdbcCatalog#8268

Open
junmuz wants to merge 1 commit into
apache:masterfrom
junmuz:fixing_jdbc_connection_leaks
Open

[core] Fix JDBC connection leak in ClientPool and JdbcCatalog#8268
junmuz wants to merge 1 commit into
apache:masterfrom
junmuz:fixing_jdbc_connection_leaks

Conversation

@junmuz

@junmuz junmuz commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Purpose

Fixes the Jdbc connection leaks that happen when Flink TMs restart.
Issue: #8267

Tests

There are some tests added specially the testConnectionClosedWhenPoolClosedDuringAction that simulates the scenario.

@junmuz junmuz force-pushed the fixing_jdbc_connection_leaks branch from 7f16f08 to 05dee59 Compare June 17, 2026 16:40
@junmuz

junmuz commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@JingsongLi Can I get a review on the PR?

@JingsongLi

Copy link
Copy Markdown
Contributor

I found one remaining leak race in ClientPool.run. The check at lines 71-72 is not atomic with returning the borrowed client to the deque: a thread can observe this.clients != null, then another thread calls close(), sets this.clients = null and drains the deque, and then the first thread executes clients.addFirst(client) on the old deque. That client was not included in the drain and is no longer reachable from the pool, so it is still left unclosed. This is the same close-during-action case this PR is trying to handle, just with a narrower interleaving. The return-to-pool path and close() need to be made mutually exclusive, or the code needs a post-add closed check/removal that closes the client if the pool was closed concurrently.

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.

2 participants