davsclaus opened a new pull request, #31388: URL: https://github.com/apache/camel/pull/31388
# Description [CAMEL-28117](https://issues.apache.org/jira/browse/CAMEL-28117): when a netty-http consumer stops, or is suspended with `send503whenSuspended=false`, the server closes only its listening channel. With a configured `workerGroup`, the connections it accepted stay open. **Cause.** camel-netty tracks accepted connections in `ServerChannelHandler.channelActive`, which adds each channel to the channel group that `SingleTCPNettyServerBootstrapFactory.stopServerBootstrap()` closes. The netty-http pipeline uses `HttpServerMultiplexChannelHandler` instead. It picks the consumer by context path and forwards only `channelRead` to the per-consumer `HttpServerChannelHandler`, so `channelActive` never reaches it and the group stays empty. The default setup hides this: the server creates its own worker group and shuts it down on stop, which closes the sockets anyway. A configured `workerGroup` is not shut down by the server, so kept-alive connections survived the stop. **Fix.** `HttpServerMultiplexChannelHandler` adds the accepted channel to the server bootstrap factory in `channelActive` (and removes it in `channelInactive`), as `ServerChannelHandler` does. All consumers of one multiplex handler listen on the same address and share one bootstrap factory. That factory stops only when its last consumer is removed, so stopping one of several routes on a port still keeps the connections open for the others. This also covers the deprecated shared HTTP server, which uses the same handler. **Test.** `NettyHttpStopClosesConnectionsTest` uses a configured `workerGroup` and a raw keep-alive connection: - stopping one of two routes on a port keeps the connection, and stopping the last one closes it; - suspending a route with `send503whenSuspended=false` closes it, and after a resume a new connection is kept alive. Both test methods fail on main (the connection is still open after 20 s) and pass with the fix. The camel-netty-http module tests pass locally. Found while reviewing #31381 (CAMEL-28074). Once both are merged, that PR's workarounds (`NettyHttpSuspendResumeTest` keeping its own event loops, `Connection: close` in `ProxyProtocolTest`) could be dropped. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [x] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (Built `components/camel-netty-http` only; no options changed, so nothing is generated.) _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
