github-actions[bot] commented on code in PR #62391:
URL: https://github.com/apache/doris/pull/62391#discussion_r3096861403


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java:
##########
@@ -311,15 +309,15 @@ public AbstractInsertExecutor initPlan(ConnectContext 
ctx, StmtExecutor stmtExec
                             buildResult.physicalSink
                     );
                 }
-                newestTargetTableIf.readUnlock();
             } catch (Throwable e) {
-                newestTargetTableIf.readUnlock();
                 // the abortTxn in onFail need to acquire table write lock
                 if (insertExecutor != null) {
                     insertExecutor.onFail(e);
                 }
                 Throwables.throwIfInstanceOf(e, RuntimeException.class);
                 throw new IllegalStateException(e.getMessage(), e);
+            } finally {

Review Comment:
   Calling `insertExecutor.onFail(e)` before this `readUnlock()` reintroduces 
the lock-order problem the old code was explicitly avoiding. For the normal 
OLAP path, `onFail()` goes through 
`OlapInsertExecutor.abortTransactionOnFail()` -> 
`GlobalTransactionMgr.abortTransaction()` -> 
`MetaLockUtils.tryWriteLockTablesOrMetaException(...)`, which needs the same 
table's write lock. Because the current thread is still holding 
`newestTargetTableIf.readLock()`, that write-lock acquisition times out instead 
of aborting the txn immediately.
   
   Please keep the unlock ahead of `onFail()` on the exception path, and use 
`finally` only for the success / retry branches if you still want to 
deduplicate the non-error unlocks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to