You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/03/06 06:40:43 UTC

[GitHub] [incubator-kyuubi] turboFei commented on a change in pull request #2044: Remove authentication thread local objects to prevent memory leak

turboFei commented on a change in pull request #2044:
URL: https://github.com/apache/incubator-kyuubi/pull/2044#discussion_r820188033



##########
File path: kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/HadoopThriftAuthBridgeServer.scala
##########
@@ -143,38 +143,44 @@ object HadoopThriftAuthBridgeServer {
           REMOTE_ADDRESS.set(socket.getInetAddress)
           val mechanismName = saslServer.getMechanismName
           USER_AUTH_MECHANISM.set(mechanismName)
-          if (AuthMethod.PLAIN.getMechanismName.equalsIgnoreCase(mechanismName)) {
-            REMOTE_USER.set(endUser)
-            wrapped.process(in, out)
-          } else {
-            if (AuthMethod.TOKEN.getMechanismName.equalsIgnoreCase(mechanismName)) {
-              try {
-                val identifier = SaslRpcServer.getIdentifier(authId, secretMgr)
-                endUser = identifier.getUser.getUserName
-              } catch {
-                case e: InvalidToken => throw new TException(e.getMessage)
-              }
-            }
-            val clientUgi: UserGroupInformation = UserGroupInformation.createRemoteUser(endUser)
-            try {
-              REMOTE_USER.set(clientUgi.getShortUserName)
-              debug(s"SET REMOTE USER: ${REMOTE_USER.get()} from endUser: $clientUgi")
+          try {
+            if (AuthMethod.PLAIN.getMechanismName.equalsIgnoreCase(mechanismName)) {
+              REMOTE_USER.set(endUser)
               wrapped.process(in, out)
-            } catch {
-              case e: RuntimeException => e.getCause match {
-                  case t: TException => throw t
-                  case _ => throw e
+            } else {
+              if (AuthMethod.TOKEN.getMechanismName.equalsIgnoreCase(mechanismName)) {
+                try {
+                  val identifier = SaslRpcServer.getIdentifier(authId, secretMgr)
+                  endUser = identifier.getUser.getUserName
+                } catch {
+                  case e: InvalidToken => throw new TException(e.getMessage)
                 }
-              case e: InterruptedException => throw new RuntimeException(e)
-              case e: IOException => throw new RuntimeException(e)
-            } finally {
+              }
+              val clientUgi: UserGroupInformation = UserGroupInformation.createRemoteUser(endUser)
               try {
-                FileSystem.closeAllForUGI(clientUgi)
+                REMOTE_USER.set(clientUgi.getShortUserName)
+                debug(s"SET REMOTE USER: ${REMOTE_USER.get()} from endUser: $clientUgi")
+                wrapped.process(in, out)
               } catch {
-                case e: IOException =>
-                  error(s"Could not clean up file-system handles for UGI: $clientUgi", e)
+                case e: RuntimeException => e.getCause match {
+                    case t: TException => throw t
+                    case _ => throw e
+                  }
+                case e: InterruptedException => throw new RuntimeException(e)
+                case e: IOException => throw new RuntimeException(e)
+              } finally {
+                try {
+                  FileSystem.closeAllForUGI(clientUgi)
+                } catch {
+                  case e: IOException =>
+                    error(s"Could not clean up file-system handles for UGI: $clientUgi", e)
+                }
               }
             }
+          } finally {
+            REMOTE_USER.remove()
+            REMOTE_ADDRESS.remove()
+            USER_AUTH_MECHANISM.remove()

Review comment:
       BTW, USER_AUTH_MECHANISM is not used currently.




-- 
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: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org