danny0405 commented on code in PR #19812:
URL: https://github.com/apache/hudi/pull/19812#discussion_r3920216225


##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HiveQueryDDLExecutor.java:
##########
@@ -183,6 +180,12 @@ private List<CommandProcessorResponse> 
updateHiveSQLs(List<String> sqls) {
       }
     } catch (Exception e) {
       throw new HoodieHiveSyncException("Failed in executing SQL", e);
+    } finally {
+      if (previousSession != null) {
+        SessionState.setCurrentSessionState(previousSession);
+      } else {
+        SessionState.detachSession();

Review Comment:
   [P2] Restore the caller context class loader too
   
   Hive `SessionState.setCurrentSessionState` changes 
`Thread.currentThread().getContextClassLoader()` to the session conf loader, 
while `detachSession()` only removes the Hive thread-local. Thus, when 
`previousSession` is null, this finally block leaves the caller thread using 
this executor class loader; `closeDriverAndSession` has the same problem and 
can leave the thread pointing at a loader that `SessionState.close()` just 
closed. That both leaks the session loader and can break later class loading on 
long-running worker threads. Please capture the original context class loader 
before binding and restore it in the finally path, including the null-session 
case, with an assertion in the lifecycle tests.



-- 
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]

Reply via email to