-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
bugfix: Enhance 401 Error Handling by Refreshing Token in acquireClusterMetaData Method #6923
base: 2.x
Are you sure you want to change the base?
Conversation
...ery-raft/src/main/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImpl.java
Outdated
Show resolved
Hide resolved
https://github.com/apache/incubator-seata/blob/2.x/changes/zh-cn/2.x.md |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #6923 +/- ##
============================================
+ Coverage 51.80% 52.56% +0.75%
- Complexity 6462 6547 +85
============================================
Files 1122 1122
Lines 39857 39860 +3
Branches 4668 4668
============================================
+ Hits 20649 20952 +303
+ Misses 17248 16910 -338
- Partials 1960 1998 +38
|
yes I have written it |
throw new AuthenticationFailedException("Authentication failed! you should configure the correct username and password."); | ||
} | ||
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) { | ||
refreshToken(tcAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove
(StringUtils.isNotBlank(USERNAME) && StringUtils.isNotBlank(PASSWORD)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it wasn't necessary, but having validation might be good, so I made the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it wasn't necessary, but having validation might be good, so I made the changes.
I think refreshToken(tcAddress); should be placed after the condition check; otherwise, it will waste a call when the account password is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially placed it outside the condition because refreshToken checks the account, but your point makes sense, so I moved it. Thanks for the feedback!
…thod
Ⅰ. Describe what this PR did
This pull request modifies the acquireClusterMetaData method in the RaftRegistryServiceImpl class to improve the handling of 401 Unauthorized errors. When a 401 error occurs during metadata retrieval, the code now attempts to refresh the authentication token and retry the request with the new token. This enhancement ensures that the application can recover from token expiration without manual intervention, thus improving user experience and system reliability.
Ⅱ. Does this pull request fix one issue?
fixes #6919