This is an automated email from the ASF dual-hosted git repository. peacewong pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/linkis.git
commit 88eb05dd1621b1c622328f87de73b47157762466 Author: peacewong <[email protected]> AuthorDate: Tue Mar 19 21:57:57 2024 +0800 Fix duplicate try login --- .../org/apache/linkis/httpclient/AbstractHttpClient.scala | 2 +- .../authentication/AbstractAuthenticationStrategy.scala | 13 +++++++------ .../linkis/httpclient/authentication/Authentication.scala | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/AbstractHttpClient.scala b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/AbstractHttpClient.scala index ec61ebd66d..d402d7ab0b 100644 --- a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/AbstractHttpClient.scala +++ b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/AbstractHttpClient.scala @@ -150,12 +150,12 @@ abstract class AbstractHttpClient(clientConfig: ClientConfig, clientName: String s"invoke ${req.getURI} get status ${response.getStatusLine.getStatusCode} taken: ${costTime}." ) if (response.getStatusLine.getStatusCode == 401) { - tryLogin(action, getRequestUrl(action), true) val msg = Utils.tryCatch(EntityUtils.toString(response.getEntity)) { t => logger.warn("failed to parse entity", t) "" } IOUtils.closeQuietly(response) + tryLogin(action, getRequestUrl(action), true) if (attempts.size() <= 1) { logger.info("The user is not logged in, default retry once") addAttempt() diff --git a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/AbstractAuthenticationStrategy.scala b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/AbstractAuthenticationStrategy.scala index c45de8f466..30f04999c5 100644 --- a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/AbstractAuthenticationStrategy.scala +++ b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/AbstractAuthenticationStrategy.scala @@ -54,6 +54,9 @@ abstract class AbstractAuthenticationStrategy extends AuthenticationStrategy wit getKeyByUserAndURL(user, serverUrl) } + protected def getAuthenticationActionByKey(key: String): Authentication = + userNameToAuthentications.get(key) + def setClientConfig(clientConfig: ClientConfig): Unit = this.clientConfig = clientConfig def getClientConfig: ClientConfig = clientConfig @@ -61,16 +64,14 @@ abstract class AbstractAuthenticationStrategy extends AuthenticationStrategy wit def login(requestAction: Action, serverUrl: String): Authentication = { val key = getKey(requestAction, serverUrl) if (key == null) return null - if ( - userNameToAuthentications - .containsKey(key) && !isTimeout(userNameToAuthentications.get(key)) - ) { - val authenticationAction = userNameToAuthentications.get(key) + val oldAuth = getAuthenticationActionByKey(key) + if (null != oldAuth && !isTimeout(oldAuth)) { + val authenticationAction = oldAuth authenticationAction.updateLastAccessTime() authenticationAction } else { key.intern() synchronized { - var authentication = userNameToAuthentications.get(key) + var authentication = getAuthenticationActionByKey(key) if (authentication == null || isTimeout(authentication)) { authentication = tryLogin(requestAction, serverUrl) putSession(key, authentication) diff --git a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/Authentication.scala b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/Authentication.scala index e40a10cd83..18e7dddd0c 100644 --- a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/Authentication.scala +++ b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/authentication/Authentication.scala @@ -25,4 +25,6 @@ trait Authentication { def updateLastAccessTime(): Unit + def getCreateTime: Long = System.currentTimeMillis() + } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
