[core] Fix JDBC connection leak in ClientPool and JdbcCatalog#8268
[core] Fix JDBC connection leak in ClientPool and JdbcCatalog#8268junmuz wants to merge 2 commits into
Conversation
7f16f08 to
05dee59
Compare
|
@JingsongLi Can I get a review on the PR? |
|
I found one remaining leak race in |
Simplify the finally block to always add the client back to the deque first, then check if close() raced. The deque's internal lock ensures mutual exclusion between drainTo and remove, preventing both leaks and double-closes.
@JingsongLi Thanks for the comment. I have tried addressing that. |
When close() is called while a run() action is in-flight, the connection is returned to the deque after close() has already drained it. The connection is then orphaned and never closed. Fix: after returning the client to the deque, check if close() raced us (this.clients == null). If so, remove the client we just added and close it directly. Credit: extracted from apache#8268.
|
@junmuz I took a different approach in #8323 to reduce jdbc client connections via sharing per JVM. That approach can reduce connections by a large factor for high parallelism jobs. It would affect some of the logic in this PR as with shared connections we would not explicitly call close. We would still need the fix of 54a23e4 from this branch, which I have ported there. Let me know if you have any thoughts. |
Purpose
Fixes the Jdbc connection leaks that happen when Flink TMs restart.
Issue: #8267
Tests
There are some tests added specially the
testConnectionClosedWhenPoolClosedDuringActionthat simulates the scenario.