konlue opened a new pull request, #7726:
URL: https://github.com/apache/shenyu/pull/7726

   Fixes #7715.
   
   ## Summary
   
   `EventLoopNettyCustomizer#apply` creates a new `LoopResources` on every call 
and hands it to `HttpServer#runOn`, but nothing owns it: Spring Boot's server 
stop closes the bound server without disposing loops supplied by a customizer, 
so a stopped/restarted embedded server leaves its event-loop threads and 
resources behind.
   
   ## Modifications
   
   - Add a `shenyuServerLoopResources` bean with `@Bean(destroyMethod = 
"dispose")`, created from `NettyHttpProperties` (same select/worker counts and 
conditions as before).
   - Pass that bean into `EventLoopNettyCustomizer` and use 
`.runOn(loopResources)` instead of allocating a new `LoopResources` in 
`apply()`.
   - Add a lifecycle test: the bean is not disposed inside the context and is 
disposed after the context closes.
   
   ## Verifying this change
   
   - [x] New 
`ShenyuNettyWebServerConfigurationTest#testEventLoopResourcesDisposedWithContext`:
 inside `ApplicationContextRunner`, `isDisposed()` is false; after `run()` 
returns (context closed), `isDisposed()` is true. Removing `destroyMethod = 
"dispose"` makes this assertion fail (`Expected: is <true>`), restoring it 
passes.
   - [x] Targeted tests pass:
   
     ```bash
     ./mvnw -B -ntp -pl 
shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway test 
-Dtest=ShenyuNettyWebServerConfigurationTest
     ```
     4/4 green.
   
   - [x] Checkstyle passes:
   
     ```bash
     ./mvnw -B -ntp -pl 
shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway checkstyle:check
     ```
     clean.
   
   ## Notes
   
   One `LoopResources` instance per application context: server stop/start 
cycles inside the same context reuse it, and it is disposed exactly once when 
the context closes, so loops shared by a still-running server are never 
disposed early. Select/worker counts and the daemon flag are unchanged.


-- 
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]

Reply via email to