Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the status code for Raft-related requests is 401, the refreshToken should be triggered as soon as possible. #6919

Open
1 task
funky-eyes opened this issue Oct 12, 2024 · 2 comments · May be fixed by #6923
Assignees
Labels
good first issue Good for newcomers task: help-wanted Extra attention is needed

Comments

@funky-eyes
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

RaftRegistryServiceImpl#acquireClusterMetaData & watch 中,对于出现401情况只进行了重试,但是重试并不代表会触发refreshToken,而绝大多数401来源于token过期,所以应该尽快的重新获取token
In RaftRegistryServiceImpl#acquireClusterMetaData and watch, when a 401 status occurs, only a retry is performed. However, a retry does not necessarily trigger a refreshToken, and the majority of 401 errors stem from token expiration. Therefore, the token should be re-acquired as soon as possible.

    private static void acquireClusterMetaData(String clusterName, String group) throws RetryableException {
        String tcAddress = queryHttpAddress(clusterName, group);
        Map<String, String> header = new HashMap<>();
        header.put(HTTP.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
        if (isTokenExpired()) {
            refreshToken(tcAddress);
        }
        if (StringUtils.isNotBlank(jwtToken)) {
            header.put(AUTHORIZATION_HEADER, jwtToken);
        }
        if (StringUtils.isNotBlank(tcAddress)) {
            Map<String, String> param = new HashMap<>();
            param.put("group", group);
            String response = null;
            try (CloseableHttpResponse httpResponse =
                HttpClientUtil.doGet("http://" + tcAddress + "/metadata/v1/cluster", param, header, 1000)) {
                if (httpResponse != null) {
                    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                        response = EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
                    } else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                        if (StringUtils.isNotBlank(USERNAME) && StringUtils.isNotBlank(PASSWORD)) {
                            throw new RetryableException("Authentication failed!");
                        } else {
                            throw new AuthenticationFailedException("Authentication failed! you should configure the correct username and password.");
                        }
                    }
                }
                MetadataResponse metadataResponse;
                if (StringUtils.isNotBlank(response)) {
                    try {
                        metadataResponse = OBJECT_MAPPER.readValue(response, MetadataResponse.class);
                        METADATA.refreshMetadata(clusterName, metadataResponse);
                    } catch (JsonProcessingException e) {
                        LOGGER.error(e.getMessage(), e);
                    }
                }
            } catch (IOException e) {
                throw new RetryableException(e.getMessage(), e);
            }
        }
    }

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Minimal yet complete reproducer code (or URL to code):

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version(e.g. java -version):
  • Seata client/server version:
  • Database version:
  • OS(e.g. uname -a):
  • Others:
@funky-eyes funky-eyes added task: help-wanted Extra attention is needed good first issue Good for newcomers labels Oct 12, 2024
@Devendra-Kumar-Dhayal
Copy link

/assign

@o-jimin
Copy link

o-jimin commented Oct 14, 2024

Can I fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers task: help-wanted Extra attention is needed
Projects
None yet
3 participants