apache / apache/shenyu

[BUG] ShenyuClientRegisterEventPublisher.start() is not idempotent: leaked Disruptor threads + duplicate heartbeat schedulers

Open
#6,541 1 comment 0 reactions 0 assignees View on GitHub
client: register priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 9h
Merged PRs (30d)
83

Description

## Description
`ShenyuClientRegisterEventPublisher` is a singleton, but `start()` is invoked once per client listener ctor (+ once for the `publisher` bean + a Tars duplicate). Each call constructs a brand-new `DisruptorProviderManage` with its own consumer thread and its own `ShenyuClientURIExecutorSubscriber`. The subscriber's `URIS` list is `static` (shared), while each subscriber's heartbeat `executor` is an instance field scheduled in its constructor. With N `start()` calls there are N heartbeat schedulers all iterating the same shared `URIS` list.

## Location
```
shenyu-client-core/.../AbstractContextRefreshedEventListener.java:139
shenyu-client-tars/.../TarsServiceBeanEventListener.java:80
shenyu-client-autoconfig/.../ClientRegisterConfiguration.java:99-104
ShenyuClientRegisterEventPublisher.java:53-61
ShenyuClientURIExecutorSubscriber.java:50 (URIS is static)
```

## Impact
Duplicate heartbeat traffic to the admin for every registered URI (2x for Tars alone), and orphaned Disruptor consumer threads for the process lifetime.

## Suggested fix
Make `start()` idempotent (guard with an `AtomicBoolean`/`started` flag), and remove the redundant `publisher.start(...)` call in `TarsServiceBeanEventListener` line 80.

## Related existing issue(s)
#6487 covers heartbeat scheduler *stop* after one full failure; this is about *duplicate* schedulers from non-idempotent start, distinct.

_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the start() call sites in AbstractContextRefreshedEventListener.java, TarsServiceBeanEventListener.java, and ClientRegisterConfiguration.java, then inspect ShenyuClientRegisterEventPublisher.java and ShenyuClientURIExecutorSubscriber.java. Done means repeated starts no longer create duplicate heartbeat schedulers or Disruptor consumer threads, and the redundant Tars invocation is removed without changing registration behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.