Sean-Walker0 opened a new pull request, #7433:
URL: https://github.com/apache/shenyu/pull/7433
Fixes #6499
## Modifications
`ConsulInstanceRegisterRepository#watcherStart` scheduled
`watchConfigKeyValues(selectKey)` directly with `scheduleWithFixedDelay` and no
exception guard. `watchConfigKeyValues` → `getHealthServices` performs the
Consul blocking query and rethrows any error, and `ScheduledThreadPoolExecutor`
suppresses all later executions of a periodic task once an exception escapes it
— so one transient Consul error (restart, network blip) permanently stopped the
watch, and stale instances kept being served from `watcherInstanceRegisterMap`
until process restart.
The scheduled task now catches the failure, logs it, and lets the next
scheduled poll retry:
```java
watchFutures.add(this.executor.scheduleWithFixedDelay(() -> {
try {
this.watchConfigKeyValues(selectKey);
} catch (Exception e) {
// an exception escaping a fixed-delay task suppresses all later
executions,
// so a single watch failure must only be logged to keep watching
LOGGER.error("consul registry watch key: {} error", selectKey, e);
}
}, 5, Integer.parseInt(watchDelay), TimeUnit.SECONDS));
```
## Verifying this change
- [x] New
`ConsulInstanceRegisterRepositoryTest#testWatcherKeepsPollingAfterFailure` —
the first `getHealthServices` call throws, the second succeeds, and the watch
must poll at least twice. Red on the pre-fix code (`Wanted *at least* 2 times`
after the 15s window — the task died after the first failure), green after.
- [x] `./mvnw -pl shenyu-registry/shenyu-registry-consul -am test -B` — 4/4
module tests green, checkstyle clean.
## Notes
- Behavior change: watch polling survives transient errors instead of
silently dying; error visibility is unchanged (ERROR with the exception).
- Same bug family as #6500 (Eureka, fixed in #7429) and #6498 (Consul TTL
heartbeat, fixed in #7432); separate reports, separate PRs.
- Orthogonality: #7042 (open) modifies
`ConsulInstanceRegisterRepository#close` and removes `TtlScheduler#shutdown` —
different methods; its diff was compared line by line and does not touch
`watcherStart`, so the changes do not overlap.
- The regression test needs a real 5s initial schedule delay (hardcoded), so
it uses a 15s Mockito `timeout` window; noted here for review transparency.
Make sure that:
- [x] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your
changes.
- [x] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true` (module-scoped:
`shenyu-registry/shenyu-registry-consul` with `-am`, tests + checkstyle green).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]