chengyouling commented on code in PR #5019:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/5019#discussion_r2554527786


##########
huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/TokenCacheManager.java:
##########
@@ -185,25 +169,36 @@ private String createHeaders() {
         LOGGER.warn("service center do not support RBAC token, you should not 
config account info");
         return INVALID_TOKEN;
       }
+      if (Status.INTERNAL_SERVER_ERROR.getStatusCode() == 
rbacTokenResponse.getStatusCode()) {
+        // return null for server_error, so the token information can be 
re-fetched on the next call.
+        // It will prompt 'CacheLoader returned null for key xxx'
+        LOGGER.warn("service center query RBAC token error!");
+        return null;
+      }
 
-      LOGGER.info("refresh token successfully {}", 
rbacTokenResponse.getStatusCode());
+      LOGGER.info("refresh host [{}] token successfully {}", host, 
rbacTokenResponse.getStatusCode());
       return rbacTokenResponse.getToken();
     }
 
     protected long refreshTime() {
       return TOKEN_REFRESH_TIME_IN_SECONDS;
     }
 
-    public String getToken() {
+    public String getToken(String host) {
       if (!enabled()) {
         return null;
       }
-
-      try {
-        return cache.get(registryName);
-      } catch (Exception e) {
-        LOGGER.error("failed to create token", e);
-        return null;
+      String address = host;
+      if (StringUtils.isEmpty(address)) {
+        address = registryName;
+      }
+      synchronized (LOCK) {

Review Comment:
   The cache loads tokens when they are not stored during queries, and it 
involves asynchronous tasks, which may lead to concurrency issues. Caffeine 
without having trie, it is unknown whether there are any bugs.



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