[ 
https://issues.apache.org/jira/browse/HIVE-27201?focusedWorklogId=858813&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-858813
 ]

ASF GitHub Bot logged work on HIVE-27201:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Apr/23 01:02
            Start Date: 25/Apr/23 01:02
    Worklog Time Spent: 10m 
      Work Description: dengzhhu653 commented on code in PR #4180:
URL: https://github.com/apache/hive/pull/4180#discussion_r1175916767


##########
service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java:
##########
@@ -401,11 +401,11 @@ private synchronized void acquireAfterOpLock(boolean 
userAccess) {
     // set the thread name with the logging prefix.
     sessionState.updateThreadName();
 
-    try {
-      setSessionHive();
-    } catch (HiveSQLException e) {
-      throw new RuntimeException(e);
-    }
+    // If Hive.get() is being shared across different sessions,
+    // sessionHive and Hive.get() may be different, in such case,
+    // the risk of deadlock on HiveMetaStoreClient#SynchronizedHandler can 
happen.
+    // Refresh the thread-local Hive to avoid the deadlock.
+    Hive.set(sessionHive);

Review Comment:
   It's true because the `sessionHive` is bound to the session when created, 
but the thread-local hive doesn't getting updated, so there is a chance that 
the thread-local hive is being shared across sessions.
   
   I wrote a test to repro the problem: 
[TestHS2SessionHive.java](https://github.com/apache/hive/pull/4180/files#diff-04289a8e507a029093af5ebd19501996c040fd7691d500abea665e706cb5c224),
 it can reoccur without the fix.
   
    





Issue Time Tracking
-------------------

    Worklog Id:     (was: 858813)
    Time Spent: 6h 10m  (was: 6h)

> Inconsistency between session Hive and thread-local Hive may cause HS2 
> deadlock
> -------------------------------------------------------------------------------
>
>                 Key: HIVE-27201
>                 URL: https://issues.apache.org/jira/browse/HIVE-27201
>             Project: Hive
>          Issue Type: Bug
>          Components: HiveServer2
>            Reporter: Zhihua Deng
>            Assignee: Zhihua Deng
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 6h 10m
>  Remaining Estimate: 0h
>
> The HiveServer2’s server handler can switch to process the operation from 
> other session, in such case, the Hive cached in ThreadLocal is not the same 
> as the Hive in SessionState, and can be referenced by another session. 
> If the two handlers swap their sessions to process the DatabaseMetaData 
> request, and the HiveMetastoreClientFactory obtains the Hive via Hive.get(), 
> then there is a chance that the deadlock can happen.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to