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