-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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: unsafe double-checked locking in SofaRegistryServiceImpl #2642
Conversation
Because `DefaultRegistryClient` is in third-part jar, the `init` method invocation can't be moved to constructor. So the local variable is used to correct DCL and minimize the number of field reads. See also: https://lgtm.com/rules/1507076816054/
Codecov Report
@@ Coverage Diff @@
## develop #2642 +/- ##
=============================================
- Coverage 51.25% 51.24% -0.02%
+ Complexity 2819 2817 -2
=============================================
Files 556 556
Lines 17803 17803
Branches 2101 2101
=============================================
- Hits 9125 9123 -2
Misses 7818 7818
- Partials 860 862 +2
|
...a-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java
Show resolved
Hide resolved
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.
LGTM.
Please associate your GitHub account with your email.@chenxi-null |
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.
Please associate your GitHub account with your email.@chenxi-null
@xingfudeshi Is there anything wrong with my email ?
I have already associated with my GitHub account with the email chenxiCoder@gmail.com
, and it can receive notification from Github.
...a-discovery-sofa/src/main/java/io/seata/discovery/registry/sofa/SofaRegistryServiceImpl.java
Show resolved
Hide resolved
|
Because `DefaultRegistryClient` is in third-part jar, the `init` method invocation can't be moved to constructor. So the local variable is used to correct DCL and minimize the number of field reads. See also: https://lgtm.com/rules/1507076816054/
…x/double-check-lock
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.
LGTM
SofaRegistryServiceImpl
Ⅰ. Describe what this PR did
This usage of double check locking is not thread-safe, the reason is present in this PR #1599 which I submitted before.
How to fix:
Because
DefaultRegistryClient
is in third-part jar, theinit
method invocation can't be moved to the constructor.So the local variable is used to correct DCL and minimize the number of field reads.
See also: https://lgtm.com/rules/1507076816054/
Quote from the article:
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews