Skip to content

[BUG] Gateway web-server shutdown leaves its custom Netty event loops running #7715

Closed

Description

@Aias00

Current behavior

EventLoopNettyCustomizer.apply() allocates a fresh LoopResources.create("shenyu-netty", ...) and supplies it to HttpServer.runOn(). No lifecycle owner retains/disposes this custom resource. Spring Boot's server stop closes the bound server but does not dispose the supplied custom event loops.

Location

ShenyuNettyWebServerConfiguration.java:154–157.

Reproduction / validation

A probe compiled the current gateway configuration, created its actual NettyReactiveWebServerFactory with one worker/selector, bound an empty HTTP handler to an ephemeral loopback port, started the server, and called server.stop():

BEFORE_STOP loopsDisposed=false threads=1
AFTER_STOP loopsDisposed=false threads=1
AFTER_EXPLICIT_DISPOSE loopsDisposed=true threads=0

The probe captured the server's actual configured LoopResources and explicitly disposed it afterward so it left no thread/socket behind. An independent reviewer inspected Spring Boot 3.3.1 NettyWebServer.stop() and Reactor Netty 1.1.20 resource handling to confirm the ownership gap.

Impact / scope

Stopping/restarting embedded gateway servers can retain custom event-loop threads and resources from earlier lifecycles. These threads are daemon threads (true in the create call), so this issue does not claim they necessarily prevent JVM exit. The runtime reproduction checks embedded server start/stop, while missing context ownership is established by source inspection.

Suggested fix

Own the custom LoopResources through an application/server lifecycle component and dispose them when that lifecycle ends, or use the existing Spring-managed resource factory consistently. Account for bind failures and restarts, and avoid disposing loops shared by still-running servers.

Related existing work

#3284 concerns allocating HTTP client loops per request; #5047 and #6018 concern TCP proxy listeners; #3063 discusses client runOn memory usage. This report concerns the gateway HTTP server customizer and a single server's start/stop lifecycle, reproduced independently of those modules. Historical/live loop-resource searches did not find the same shutdown defect.

Reviewed revision

Apache ShenYu 2.7.2-SNAPSHOT, master@66d7d954ca37d651a5ad916f988a8081157a7ab4. Severity Medium / P2; confidence high. Unit-test and CI issue categories excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions