apache / apache/shenyu

[BUG] HttpShenyuSdkClient never shuts down CloseableHttpAsyncClient / IOReactor — non-daemon threads block JVM exit

Open
#6,854 1 comment 0 reactions 0 assignees View on GitHub
priority: medium sdk type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
`HttpShenyuSdkClient.initClient` constructs a `DefaultConnectingIOReactor`, a `PoolingNHttpClientConnectionManager`, and a `CloseableHttpAsyncClient` (started via `client.start()` at line 103), but neither `HttpShenyuSdkClient` nor `AbstractShenyuSdkClient` nor the `ShenyuSdkClient` interface defines any `close()`/`shutdown()`/`@PreDestroy`/`DisposableBean` lifecycle. The `@Bean` in `ShenyuSdkAutoConfiguration` has no `destroyMethod` and the type exposes no `close`/`AutoCloseable` method for Spring's inferred destroy to find, so nothing is ever closed on context shutdown. The `DefaultConnectingIOReactor` worker threads are non-daemon (Apache HttpCore `DefaultThreadFactory` default).

## Location
- `shenyu-sdk/shenyu-sdk-httpclient/src/main/java/org/apache/shenyu/sdk/httpclient/HttpShenyuSdkClient.java:84-105`
- `shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/client/ShenyuSdkClient.java:33-54`
- `shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/src/main/java/org/apache/shenyu/springboot/starter/sdk/ShenyuSdkAutoConfiguration.java:82-91`

## Impact
On every application-context close (Spring Boot devtools restart, test teardown, graceful shutdown), the async HTTP client, connection pool, and IO reactor leak; non-daemon reactor threads keep the JVM alive, forcing `kill -9`. Repeated context restarts accumulate leaked reactors/threads.

## Suggested fix
Add `implements AutoCloseable` (or `DisposableBean`) to `ShenyuSdkClient`/`AbstractShenyuSdkClient` with a `close()` that shuts down the `CloseableHttpAsyncClient` and `PoolingNHttpClientConnectionManager` (and ideally make reactor threads daemon); Spring will then infer the destroy method.

## Related existing
None — distinct from #6654 (LOG-02 logging-client thread pools), #6703 (UpstreamCheckService.close leaks invokeExecutor), and #6761/#6769 (logging close). No baseline entry covers `shenyu-sdk` `HttpShenyuSdkClient` lifecycle.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with HttpShenyuSdkClient.initClient at lines 84-105, then inspect the ShenyuSdkClient interface and ShenyuSdkAutoConfiguration bean at the listed locations. Trace how the async client, connection manager, and reactor are created and determine how Spring context shutdown reaches them. Done means those resources close on shutdown and their non-daemon threads no longer keep the JVM alive.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.