You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "daguimu (via GitHub)" <gi...@apache.org> on 2026/03/27 03:28:04 UTC

[PR] fix(remoting): stop ReconnectTimerTask when client is closed [dubbo]

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

   ## Problem
   
   After all providers go offline, the consumer's `ReconnectTimerTask` keeps attempting to reconnect to the old provider IP indefinitely. In K8s environments where providers restart with new IPs, this generates continuous connection-refused errors and triggers false alerts.
   
   ## Root Cause
   
   Three issues allow the reconnect timer to run indefinitely after a client should be considered closed:
   
   1. **`AbstractTimerTask.run()`** always reschedules the timer via `reput()`, even when all channels are already closed. The task becomes an orphaned timer doing nothing but consuming resources.
   
   2. **`HeaderExchangeClient.isClosed()`** only checks `HeaderExchangeChannel.closed` but not the underlying `Client.isClosed()`. When the underlying `AbstractClient`/`NettyClient` is closed independently (e.g., by protocol destroy), the `HeaderExchangeClient` still reports as open.
   
   3. **`ReconnectTimerTask.doTask()`** has no defensive check for client closure before attempting reconnection. Even if the client is closed between the `run()` check and the `doTask()` execution, reconnection proceeds.
   
   ## Fix
   
   - **`AbstractTimerTask.run()`**: When all channels report as closed, cancel the timer task instead of rescheduling. This prevents orphaned timers from running indefinitely.
   
   - **`HeaderExchangeClient.isClosed()`**: Also check `client.isClosed()` so that if the underlying client is closed by any code path, the wrapper correctly reflects the closed state.
   
   - **`ReconnectTimerTask.doTask()`**: Add a defensive check at the start — if the channel is a `Client` and reports as closed, cancel the timer and return immediately.
   
   ## Tests Added
   
   | Change Point | Test |
   |---|---|
   | AbstractTimerTask auto-cancel on all channels closed | `AbstractTimerTaskTest.testAutoCancelWhenAllChannelsClosed()` — verifies task stops executing and cancel flag is set after channel closes |
   | AbstractTimerTask continues when channel is open | `AbstractTimerTaskTest.testTaskContinuesWhenChannelIsOpen()` — regression test ensuring normal scheduling works |
   | HeaderExchangeClient.isClosed() checks underlying client | `HeaderExchangeClientTest.testIsClosedWhenUnderlyingClientClosed()` — verifies isClosed() returns true when underlying client is closed |
   | HeaderExchangeClient.isClosed() normal case | `HeaderExchangeClientTest.testIsNotClosedWhenBothOpen()` — regression test for normal open state |
   | ReconnectTimerTask stops on client close | `ReconnectTimerTaskTest.testStopReconnectWhenClientClosed()` — verifies reconnect count stops increasing and timer is cancelled after client closes |
   | ReconnectTimerTask continues when not closed | `ReconnectTimerTaskTest.testReconnectContinuesWhenNotClosed()` — regression test ensuring reconnection works for transient disconnections |
   
   ## Impact
   
   Only affects `HeaderExchangeClient`-based connections (Dubbo protocol). The newer `AbstractNettyConnectionClient` (Triple protocol) already handles this correctly via `NettyConnectionHandler`. No behavioral change for normal reconnection scenarios — the timer still runs for transient disconnections where the client is not closed.
   
   Fixes #15880


-- 
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(remoting): stop ReconnectTimerTask when client is closed [dubbo]

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

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/16176?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 `16.66667%` with `5 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 36.93%. Comparing base ([`b54059d`](https://app.codecov.io/gh/apache/dubbo/commit/b54059dac4ecadc46a65a2c0b3244589fb3892cb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`94d98b6`](https://app.codecov.io/gh/apache/dubbo/commit/94d98b6af8ef18abfc45e548d2cc47519a0fd2c2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 7 commits behind head on 3.3.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/dubbo/pull/16176?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ing/exchange/support/header/AbstractTimerTask.java](https://app.codecov.io/gh/apache/dubbo/pull/16176?src=pr&el=tree&filepath=dubbo-remoting%2Fdubbo-remoting-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fremoting%2Fexchange%2Fsupport%2Fheader%2FAbstractTimerTask.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZW1vdGluZy9leGNoYW5nZS9zdXBwb3J0L2hlYWRlci9BYnN0cmFjdFRpbWVyVGFzay5qYXZh) | 20.00% | [2 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../exchange/support/header/HeaderExchangeClient.java](https://app.codecov.io/gh/apache/dubbo/pull/16176?src=pr&el=tree&filepath=dubbo-remoting%2Fdubbo-remoting-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fremoting%2Fexchange%2Fsupport%2Fheader%2FHeaderExchangeClient.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZW1vdGluZy9leGNoYW5nZS9zdXBwb3J0L2hlYWRlci9IZWFkZXJFeGNoYW5nZUNsaWVudC5qYXZh) | 0.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16176?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 (b54059d) and HEAD (94d98b6). Click for more details.
   > 
   > <details><summary>HEAD has 5 uploads less than BASE</summary>
   >
   >| Flag | BASE (b54059d) | HEAD (94d98b6) |
   >|------|------|------|
   >|unit-tests-java17|1|0|
   >|unit-tests-java8|1|0|
   >|unit-tests-java25|1|0|
   >|unit-tests-java11|1|0|
   >|unit-tests-java21|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##                3.3   #16176       +/-   ##
   =============================================
   - Coverage     60.80%   36.93%   -23.87%     
   + Complexity    11767    11737       -30     
   =============================================
     Files          1953     1952        -1     
     Lines         89118    89101       -17     
     Branches      13444    13362       -82     
   =============================================
   - Hits          54190    32912    -21278     
   - Misses        29367    51603    +22236     
   + Partials       5561     4586      -975     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/dubbo/pull/16176/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/16176/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.11% <16.66%> (-0.07%)` | :arrow_down: |
   | [integration-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16176/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.22% <16.66%> (-0.03%)` | :arrow_down: |
   | [samples-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16176/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.13% <0.00%> (-0.04%)` | :arrow_down: |
   | [samples-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16176/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.72% <0.00%> (-0.01%)` | :arrow_down: |
   | [unit-tests-java11](https://app.codecov.io/gh/apache/dubbo/pull/16176/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/16176/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/16176/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/16176/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/16176/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 Sentry](https://app.codecov.io/gh/apache/dubbo/pull/16176?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