[HUDI-5993] Connection leak for lock provider#8304
Conversation
| if (writeConfig.getWriteConcurrencyMode().supportsOptimisticConcurrencyControl()) { | ||
| getLockProvider().unlock(); | ||
| metrics.updateLockHeldTimerMetrics(); | ||
| close(); |
There was a problem hiding this comment.
Nice catch, can we write a UT to guard this logic?
There was a problem hiding this comment.
We new many txn managers for each fresh new txn, like in all kinds of action executors, we execute a beginTransaction and endTransaction for each of the txn but missing to call the #close explicitly.
There was a problem hiding this comment.
Of course, it depends on whether we want to keep the long live connection or short live connection, if we fix the code like this patch does, the connection becomes short lived.
A long lived connection is more risky for connection leaks, we need to care about the life cycle of the connection, we need to consider resuing the existing connections, which makes the things more complicated and hard to keep correctness.
There was a problem hiding this comment.
@vinothchandar : yes you are right. for streaming ingestion, we keep re-using the same write client and hence.
| assertNotNull(lockProvider.get(lockManager)); | ||
|
|
||
| assertDoesNotThrow(() -> { | ||
| lockManager.unlock(); |
There was a problem hiding this comment.
We can use the mockito to check the #close method invoke instead, take TestCloudWatchMetricsReporter for an example.
|
LGTM. |
* close lockProvider when we do unlock
* close lockProvider when we do unlock
* close lockProvider when we do unlock
* close lockProvider when we do unlock
* close lockProvider when we do unlock

Change Logs
Enable occ with ZookeeperBasedLockProvider, when the job runs for a while, it throws a CuratorConnectionLossException. And I find
Too many connectionsin zk log.This pr calls TransactionManager.close after endTransaction
Impact
none
Risk level (write none, low medium or high below)
low
Documentation Update
Describe any necessary documentation update if there is any new feature, config, or user-facing change
ticket number here and follow the instruction to make
changes to the website.
Contributor's checklist