apache / apache/shenyu

[BUG] Client heartbeat scheduler can stop permanently after one full failure

Open
#6,487 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Current Behavior

Client heartbeat reporting can permanently stop after one heartbeat cycle fails against all configured admin servers.

The heartbeat tasks are scheduled with `scheduleAtFixedRate(...)`:

```java
executor.scheduleAtFixedRate(() -> URIS.forEach(this::sendHeartbeat), 30, 10, TimeUnit.SECONDS);
```

The HTTP register repository throws from the heartbeat path when the last admin server fails or when an access token cannot be resolved:

```java
if (StringUtils.isBlank(accessToken)) {
throw new NullPointerException("accessToken is null");
}
...
if (i == serverList.size()) {
throw new RuntimeException(e);
}
```

For `ScheduledThreadPoolExecutor.scheduleAtFixedRate`, an exception escaping the task suppresses subsequent executions of that periodic task. So a single full-cluster outage or token failure can stop future heartbeats until the client process restarts.

### Expected Behavior

A failed heartbeat cycle should be logged and retried on the next scheduled run. Exceptions should not escape the periodic heartbeat runnable.

### Steps to Reproduce

1. Configure a Shenyu client with HTTP register/heartbeat enabled.
2. Make all configured admin servers temporarily unreachable, or make token acquisition return blank.
3. Let one heartbeat cycle run.
4. Restore admin availability.
5. The scheduled heartbeat task may no longer run because the prior exception escaped the fixed-rate task.

### Code Location

- `shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/disruptor/subcriber/ShenyuClientURIExecutorSubscriber.java`
- `shenyu-register-center/shenyu-register-client-beat/src/main/java/org/apache/shenyu/register/client/beat/HeartbeatListener.java`
- `shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/main/java/org/apache/shenyu/register/client/http/HttpClientRegisterRepository.java`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the scheduling path in shenyu-client/.../ShenyuClientURIExecutorSubscriber.java, then trace heartbeat handling through HeartbeatListener.java and HttpClientRegisterRepository.java. Reproduce a full admin-server failure or blank access token and verify that the failure is logged, the periodic task remains scheduled, and a later run succeeds after availability is restored.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.