Commit afda007
authored
* test(client): add regression test for NPE in checkListenCache when server returns unknown key
Reproduces the same bug class fixed by #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>
* fix(client): regression of NPE in ConfigRpcTransportClient.checkListenCache (re-introduces #9461)
The original fix in #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>
---------
Signed-off-by: wushiyuanmaimob <wushiyuanwork@outlook.com>
1 parent 1a5386f commit afda007
2 files changed
Lines changed: 107 additions & 15 deletions
File tree
- client/src
- main/java/com/alibaba/nacos/client/config/impl
- test/java/com/alibaba/nacos/client/config/impl
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1048 | 1048 | | |
1049 | 1049 | | |
1050 | 1050 | | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1055 | 1059 | | |
| 1060 | + | |
| 1061 | + | |
1056 | 1062 | | |
1057 | 1063 | | |
1058 | 1064 | | |
| |||
1174 | 1180 | | |
1175 | 1181 | | |
1176 | 1182 | | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
| 1183 | + | |
1181 | 1184 | | |
1182 | 1185 | | |
1183 | 1186 | | |
| |||
1188 | 1191 | | |
1189 | 1192 | | |
1190 | 1193 | | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
| 1194 | + | |
1195 | 1195 | | |
1196 | 1196 | | |
1197 | 1197 | | |
| |||
Lines changed: 95 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | 598 | | |
602 | 599 | | |
603 | 600 | | |
| |||
643 | 640 | | |
644 | 641 | | |
645 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
646 | 738 | | |
647 | 739 | | |
648 | 740 | | |
| |||
0 commit comments