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
fix #11986 ConcurrentHashMapUtils lock bug #11987
Conversation
issue : #11986 |
@AlbumenJ 限定到了jdk8,看行不行。 |
// https://github.com/apache/dubbo/issues/11986 | ||
final ConcurrentHashMap<String,Integer> map=new ConcurrentHashMap<>(); | ||
// // map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42)); | ||
if (JRE.JAVA_8.isCurrentVersion()) { |
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.
这里应该任何版本的 JDK 都应该可以使用吧
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.
并不是。这个bug在JDK8下会造成循环调用,但是jdk9+修复了这个问题,解决方式是有循环调用则抛出异常。这个test在jdk8下通过,jdk9+抛出异常。
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.
那基于 junit5 的注解做两个测试吧
现在 PR的 UT 只跑 JDK17,JDK 8 11 17 的全量测试只有 scheduled 的时候跑
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.
@AlbumenJ 是这个意思么?我拆分成两个test。
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.
@EnabledForJreRange(max = JRE.JAVA_8)
@EnabledForJreRange(min = JRE.JAVA_9)
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.
写两个 test,分别通过 EnabledForJreRange 配置运行的 jdk 版本
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.
@AlbumenJ 辛苦看下。
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.
#6032
ExtensionLoader以前也遇到过这种问题,这样修改后代码健壮性挺好的
// https://github.com/apache/dubbo/issues/11986 | ||
final ConcurrentHashMap<String,Integer> map=new ConcurrentHashMap<>(); | ||
// // map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42)); | ||
if (JRE.JAVA_8.isCurrentVersion()) { |
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.
那基于 junit5 的注解做两个测试吧
现在 PR的 UT 只跑 JDK17,JDK 8 11 17 的全量测试只有 scheduled 的时候跑
Codecov Report
@@ Coverage Diff @@
## 3.2 #11987 +/- ##
============================================
- Coverage 69.40% 69.35% -0.06%
Complexity 2 2
============================================
Files 1605 1605
Lines 66165 66171 +6
Branches 9698 9701 +3
============================================
- Hits 45924 45893 -31
- Misses 15811 15841 +30
- Partials 4430 4437 +7 see 24 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
// https://github.com/apache/dubbo/issues/11986 | ||
final ConcurrentHashMap<String,Integer> map=new ConcurrentHashMap<>(); | ||
// // map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42)); | ||
if (JRE.JAVA_8.isCurrentVersion()) { |
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.
写两个 test,分别通过 EnabledForJreRange 配置运行的 jdk 版本
…o into 3.2-fixConcurrentHashMapUtils
// JDK8下,由于循环调用bug,会造成执行computeIfAbsent死循环问题 | ||
// ConcurrentHashMapUtils.computeIfAbsent用于解决此问题,保证正常执行 |
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 comment in English
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.
@AlbumenJ check it, please.
…o into 3.2-fixConcurrentHashMapUtils
// v = map.computeIfAbsent(key, func); | ||
|
||
// this bug fix methods maybe cause `func.apply` multiple calls. | ||
v = func.apply(key); |
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.
Will this allocate more memory?
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.
yes
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.
@chickenlj @CrazyHZM PTAL
dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConcurrentHashMapUtils.java
Show resolved
Hide resolved
…o into 3.2-fixConcurrentHashMapUtils
Kudos, SonarCloud Quality Gate passed! |
What is the purpose of the change
fix ConcurrentHashMapUtils lock bug
Brief changelog
Verifying this change
Closed #11986
Checklist