You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Zhengcy05 (via GitHub)" <gi...@apache.org> on 2026/06/10 08:32:56 UTC

[PR] Fix unconnected Curator client handling when registry check is false [dubbo]

Zhengcy05 opened a new pull request, #16329:
URL: https://github.com/apache/dubbo/pull/16329

   Fixes #16186 
   
   ## What is the purpose of the change?
   
   This PR fixes an issue in the multi-ZooKeeper registry scenario when one registry is unavailable and configured with `check=false`.
   
   Based on the issue report, in the `dubbo 3.3` branch, if multiple ZooKeeper registries are configured and one of them is not started with `check=false`, `Curator5ZookeeperClient` may keep an unconnected Curator client alive after `blockUntilConnected(...)` returns `false`. As a result, the following registry workflow still treats that client as usable and continues trying to create nodes on it. This can cause repeated failures in node creation, significantly slow down application startup, and eventually lead to startup failure.
   
   From the call path, the problem has two parts:
   
   1. `Curator5ZookeeperClient` does not fail fast enough on connection failure  
      If `blockUntilConnected(...)` returns `false`, the ZooKeeper client has not been successfully established. This should always be treated as a client creation failure, and the underlying Curator client should be closed immediately so it cannot be reused later.  
      The `check=false` semantic should only control whether the upper layer continues to throw when registry creation fails. It should not change whether the low-level ZooKeeper client itself is considered successfully created.
   
   2. `ListenerRegistryWrapper` is not null-safe when the upper layer returns a `null` registry  
      In `AbstractRegistryFactory#getRegistry()`, when registry creation fails and `check=false`, Dubbo logs a warning and returns `null`.  
      However, `RegistryFactoryWrapper` still wraps that result, and methods such as `ListenerRegistryWrapper#getUrl()` previously dereferenced the delegate directly. This could later trigger a `NullPointerException` in paths like `RegistryDirectory#subscribe()`.
   
   To address this, this PR includes two parts:
   
   - Fix the connection failure handling in `Curator5ZookeeperClient`
     - When `blockUntilConnected(...) == false`, always close the client first and then throw an exception.
     - Remove the dependency on `check` in this low-level failure path.
     - Keep the client creation semantic consistent: if the connection is not established, client creation fails.
   
   - Add null-safe handling to `ListenerRegistryWrapper`
     - Add a constructor that preserves the original `URL`.
     - Return the original URL from `getUrl()` when `registry == null`.
     - Return `false` from `isAvailable()` when `registry == null`.
     - Make `destroy()` a safe no-op when `registry == null`.
     - Add null protection to `unsubscribe()`, `isServiceDiscovery()`, and `lookup()`.
     - Keep the existing listener callback behavior unchanged.
   
   With these changes:
   
   - an unconnected ZooKeeper client will not be reused by the following registry workflow;
   - the existing `check=false` behavior at the registry factory layer remains unchanged;
   - a `null` registry can still be safely wrapped without introducing extra NPEs.
   
   ## Tests
   
   This PR adds focused regression coverage for both the low-level client behavior and the upper-layer `check=false` flow:
   
   - `Curator5ZookeeperClientTest`
     - verifies that when `blockUntilConnected(...)` fails, constructing `Curator5ZookeeperClient` throws `IllegalStateException` for both `check=true` and `check=false`;
     - verifies that `client.close()` is invoked on connection failure.
   
   - `AbstractRegistryFactoryTest`
     - verifies that when `createRegistry(url)` fails and `check=false`, `getRegistry(url)` returns `null`, preserving the existing upper-layer behavior.
   
   - `ListenerRegistryWrapperTest`
     - verifies that `getUrl()`, `isAvailable()`, `destroy()`, `lookup()`, `subscribe()`, and `unsubscribe()` are safe when `registry == null`;
     - verifies that listener callbacks are still triggered as expected in the `null registry` case.
   
   - `RegistryFactoryWrapperTest`
     - verifies that when the underlying `RegistryFactory#getRegistry(url)` returns `null`, the wrapper still returns the original URL safely and allows subscription-related calls without throwing exceptions.
   
   Verification command used:
   
   ```bash
   mvn -pl dubbo-remoting/dubbo-remoting-zookeeper-curator5,dubbo-registry/dubbo-registry-api \
     -Dtest=Curator5ZookeeperClientTest,ListenerRegistryWrapperTest,RegistryFactoryWrapperTest,AbstractRegistryFactoryTest \
     -Dsurefire.failIfNoSpecifiedTests=false test -q
   ```
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] Fix unconnected Curator client handling when registry check is false [dubbo]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #16329:
URL: https://github.com/apache/dubbo/pull/16329#issuecomment-4677089101

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/16329?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `26.66667%` with `11 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 35.30%. Comparing base ([`c3ceb27`](https://app.codecov.io/gh/apache/dubbo/commit/c3ceb276ffc0c0f8e8ffca2282a990440150aa73?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c37cb02`](https://app.codecov.io/gh/apache/dubbo/commit/c37cb023c633ed184a1fd23b517640a1c60bdb58?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/dubbo/pull/16329?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...apache/dubbo/registry/ListenerRegistryWrapper.java](https://app.codecov.io/gh/apache/dubbo/pull/16329?src=pr&el=tree&filepath=dubbo-registry%2Fdubbo-registry-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fregistry%2FListenerRegistryWrapper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVnaXN0cnkvZHViYm8tcmVnaXN0cnktYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZWdpc3RyeS9MaXN0ZW5lclJlZ2lzdHJ5V3JhcHBlci5qYXZh) | 25.00% | [5 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...registry/zookeeper/util/CuratorFrameworkUtils.java](https://app.codecov.io/gh/apache/dubbo/pull/16329?src=pr&el=tree&filepath=dubbo-registry%2Fdubbo-registry-zookeeper%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fregistry%2Fzookeeper%2Futil%2FCuratorFrameworkUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVnaXN0cnkvZHViYm8tcmVnaXN0cnktem9va2VlcGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZWdpc3RyeS96b29rZWVwZXIvdXRpbC9DdXJhdG9yRnJhbWV3b3JrVXRpbHMuamF2YQ==) | 0.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (c3ceb27) and HEAD (c37cb02). Click for more details.
   > 
   > <details><summary>HEAD has 6 uploads less than BASE</summary>
   >
   >| Flag | BASE (c3ceb27) | HEAD (c37cb02) |
   >|------|------|------|
   >|samples-tests-java21|1|0|
   >|unit-tests-java25|1|0|
   >|unit-tests-java8|1|0|
   >|unit-tests-java11|1|0|
   >|unit-tests-java21|1|0|
   >|unit-tests-java17|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##                3.3   #16329       +/-   ##
   =============================================
   - Coverage     60.79%   35.30%   -25.49%     
   + Complexity    11777    11206      -571     
   =============================================
     Files          1953     1952        -1     
     Lines         89208    89190       -18     
     Branches      13458    13374       -84     
   =============================================
   - Hits          54234    31492    -22742     
   - Misses        29403    53164    +23761     
   + Partials       5571     4534     -1037     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [integration-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.12% <26.66%> (+<0.01%)` | :arrow_up: |
   | [integration-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.23% <26.66%> (-0.09%)` | :arrow_down: |
   | [samples-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [samples-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.72% <20.00%> (-0.15%)` | :arrow_down: |
   | [unit-tests-java11](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java17](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java25](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16329/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo/pull/16329?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org