Skip to content

[ISSUE #15225] Fix regression of #9461: NPE in ConfigRpcTransportClient.checkListenCache - #15226

Merged
KomachiSion merged 2 commits into
alibaba:developfrom
wushiyuanmaimob:fix/clientworker-npe-regression-9461
May 25, 2026
Merged

KomachiSion merged 2 commits into
alibaba:developfrom
wushiyuanmaimob:fix/clientworker-npe-regression-9461

Conversation

@wushiyuanmaimob

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fix a regression of PR #9461. ConfigRpcTransportClient.checkListenCache may
throw NullPointerException when the server returns a changeKey in
ConfigChangeBatchListenResponse that has been concurrently removed from
the local cacheMap (e.g. user has just called removeListener).

The unsafe pattern cacheMap.get().get(changeKey).isInitializing() was
originally fixed in PR #9461 (milestone 2.2.0, commit c8c64a1) by moving
the notify computation into refreshContentAndCheck to share its existing
null-check. When the gRPC long-connection variant ConfigRpcTransportClient
was introduced in 3.x, a fresh copy of refreshContentAndCheck(RpcClient, String, boolean) was added — its body has a defensive null-check, but the
two callers (lines 1125 and 1136 in 3.1.1) re-introduced the unsafe
pre-dereference, defeating the protection.

The NPE is currently swallowed by the surrounding catch (Throwable) and
only surfaces as Execute listen config change error log noise, but the
batch processing of remaining changeKeys is aborted whenever it triggers.

Brief changelog

  • Refactor ConfigRpcTransportClient.refreshContentAndCheck(RpcClient, String, boolean) to refreshContentAndCheck(RpcClient, String) —
    notify = !cache.isInitializing() is now computed inside the method,
    under the existing cache != null guard.
  • Take a single cacheMap.get() snapshot to avoid duplicate volatile reads
    and replace containsKey + get double-lookup with a single get + null check.
  • Simplify the two unsafe call sites in checkListenCache accordingly.
  • Add regression test ClientWorkerTest#testCheckListenCacheSkipsRemovedKey
    that asserts no NPE-induced batch abort when the server returns an unknown
    changeKey.

Verifying this change

  • New unit test ClientWorkerTest#testCheckListenCacheSkipsRemovedKey
    FAILS on 3.1.1 (NPE aborts the listenCaches loop) and PASSES with this
    change.
  • Existing ClientWorkerTest#testExecuteConfigListen still passes —
    confirming the simpler call signature is behavior-preserving on the happy
    path.
  • Full ClientWorkerTest (28 tests): all pass.
  • Full client module (683 tests): all pass.
  • mvn -B clean package apache-rat:check -Dmaven.test.skip=true -pl client -am ✅
  • mvn clean install -DskipITs -pl client -am ✅
  • mvn checkstyle:check -pl client ✅
  • mvn pmd:check -pl client ✅

Follow this checklist to help us incorporate your contribution quickly and easily:

Closes #15225


@CLAassistant

CLAassistant commented May 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API、新增配置参数、修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@github-actions

Copy link
Copy Markdown

⚠️ Commit Author Verification Failed

The following commits have author emails not linked to any GitHub account.
This will prevent CLA signing and block your PR from being merged.

Commit Author Email
cd5928a sywu14 sywu14@iflytek.com
38513e2 sywu14 sywu14@iflytek.com

How to fix:

  1. Add your commit email to your GitHub account: https://github.com/settings/emails
  2. Or update your local git config to use an email already linked to GitHub:
    git config user.name "Your GitHub Username"
    git config user.email "your-github-email@example.com"
    
  3. Amend your commits and force-push:
    git rebase -i HEAD~2 # mark commits as "edit" and amend author
    git push --force-with-lease
    

This check will re-run automatically after you push.

@wushiyuanmaimob
wushiyuanmaimob force-pushed the fix/clientworker-npe-regression-9461 branch 2 times, most recently from f328c42 to b24d52d Compare May 23, 2026 13:02
@wushiyuanmaimob

Copy link
Copy Markdown
Contributor Author

The earlier "Commit Author Verification Failed" notice references obsolete SHAs
(cd5928a, 38513e2) from the initial push. After amending the author email,
the current head (b24d52d) passes the "Verify commit author emails" check
and CLA has been signed.

之前 bot 提示的 author email 校验失败是基于旧 commit (cd5928a / 38513e2)
的初次 push。amend 邮箱后当前 head (b24d52d) 已通过 "Verify commit author
emails" 检查,CLA 也已签署,可正常 review。

KomachiSion
KomachiSion previously approved these changes May 25, 2026
@KomachiSion

Copy link
Copy Markdown
Collaborator

大概率 spotless会无法通过, 我有看到缩进被修改了。

…rver returns unknown key

Reproduces the same bug class fixed by alibaba#9461: when the server returns a
changeKey in ConfigChangeBatchListenResponse that has been concurrently
removed from the local cacheMap (e.g. user has just called removeListener),
the unsafe pre-dereference cacheMap.get().get(changeKey).isInitializing()
throws NPE. The exception is swallowed by the surrounding catch (Throwable)
and only surfaces as "Execute listen config change error" log noise, but the
batch processing of the remaining changeKeys is silently aborted.

The new test ClientWorkerTest#testCheckListenCacheSkipsRemovedKey asserts
that no NPE-induced batch abort happens when the server returns an unknown
changeKey. Without the fix the test fails because the swallowed NPE leaves
the local cache's isInitializing() flag unchanged.

Assisted-by: Claude Code
Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
…nCache (re-introduces alibaba#9461)

The original fix in alibaba#9461 (milestone 2.2.0, commit c8c64a1) moved the
notify computation into refreshContentAndCheck so that the existing
cache != null guard would protect both call sites. When the gRPC long-
connection variant ConfigRpcTransportClient was introduced in 3.x, a fresh
copy of refreshContentAndCheck(RpcClient, String, boolean) was added — its
body has a defensive null-check, but the two callers re-introduced the
unsafe pattern cacheMap.get().get(changeKey).isInitializing(), defeating
the protection.

Refactor refreshContentAndCheck(RpcClient, String, boolean) to
refreshContentAndCheck(RpcClient, String) so notify = !cache.isInitializing()
is computed inside the method, under the existing cache != null guard.
Take a single cacheMap.get() snapshot to avoid duplicate volatile reads
and replace containsKey + get double-lookup with a single get + null check.

Assisted-by: Claude Code
Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
@wushiyuanmaimob

Copy link
Copy Markdown
Contributor Author

大概率 spotless会无法通过, 我有看到缩进被修改了。

Thanks for the heads-up. Spotless violations fixed locally and force-pushed.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...alibaba/nacos/client/config/impl/ClientWorker.java 60.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@KomachiSion
KomachiSion merged commit afda007 into alibaba:develop May 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression of #9461: NPE in ConfigRpcTransportClient.checkListenCache when server returns unknown changeKey

4 participants