fix(config): guard NPE in getGrayLastModifiedTs and add volatile to DCL - #15669
Open
srpatcha wants to merge 1 commit into
Open
fix(config): guard NPE in getGrayLastModifiedTs and add volatile to DCL#15669srpatcha wants to merge 1 commit into
srpatcha wants to merge 1 commit into
Conversation
Two issues in the config module: 1. ConfigCacheService.getGrayLastModifiedTs dereferenced the CacheItem returned by CACHE.get(groupKey) without a null check, even though that map lookup can return null. Every sibling method (getContentGrayMd5, getGrayRule) already guards item == null. Added the missing guard so a non-existent group key returns 0 instead of throwing a NullPointerException. 2. ConfigDiskServiceFactory used double-checked locking on a non-volatile static field. Without volatile, the Java Memory Model allows a thread to observe a non-null reference to a partially-constructed object. Declared configDiskService volatile for safe publication. Also adds a regression assertion in ConfigCacheServiceTest covering the non-existent group key path for getGrayLastModifiedTs. Fixes alibaba#15625 Signed-off-by: Srikanth Patchava <spatchava@meta.com>
|
Thanks for your this PR. 🙏 感谢您提交的PR。 🙏 |
Collaborator
|
duplicated PR, reference:#15666 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Fixes #15625
Two targeted correctness fixes in the
configmodule.1. NPE in
ConfigCacheService.getGrayLastModifiedTsThe method dereferenced the
CacheItemreturned byCACHE.get(groupKey)without a null check, even though that lookup can returnnull. Every sibling method (getContentGrayMd5,getGrayRule) already guardsitem == null. A query for a non-existent group key would throw aNullPointerExceptioninstead of returning0.2. Broken double-checked locking in
ConfigDiskServiceFactoryThe singleton used double-checked locking but the static field was not
volatile. Withoutvolatile, the JMM permits a thread to observe a non-null reference to a partially-constructed object (classic broken DCL). Declared the fieldvolatilefor safe publication.Brief changelog
ConfigCacheService.getGrayLastModifiedTs: additem == nullguard consistent with sibling methods.ConfigDiskServiceFactory.configDiskService: markvolatile.ConfigCacheServiceTest.testGetGrayLastModifiedTs: add regression assertion for the non-existent group-key path.Verifying this change
testGetGrayLastModifiedTsextended to assertgetGrayLastModifiedTs("noKey", grayName) == 0(previously would NPE).