allthingssecurity opened a new pull request, #30355: URL: https://github.com/apache/camel/pull/30355
# Description [CAMEL-27172](https://issues.apache.org/jira/browse/CAMEL-27172) With `sync=true` and `requestTimeout`, the netty producer relies on a `ReadTimeoutHandler` named `timeout` in the channel pipeline. `ClientChannelHandler.channelRead0` removes it when a reply arrives, and only `activateObject` of the producer pool adds it again, when a channel is borrowed from the `GenericObjectPool` (CAMEL-14363 added that; `NettyRequestTimeoutTest.testKeepingTimeoutHeader` covers it). Two documented options use a channel again without that borrow: - `producerPoolEnabled=false`: `SharedSingletonObjectPool.borrowObject` returns the same channel and never calls `activateObject`; - `reuseChannel=true`: the second and later calls of the same exchange take the channel from the `CamelNettyChannel` exchange property. So every request after the first one on that channel has no timeout: when the server does not answer, the caller waits for ever (the default correlation manager has no timeout of its own). The `CamelNettyRequestTimeout` header still works, as it adds the handler for its request. Fix: `processWithConnectedChannel` adds a `ReadTimeoutHandler` with the configured `requestTimeout` when the producer is sync and the channel has none (the same check as `activateObject`, at send time). A pooled channel keeps the handler `activateObject` added, so nothing changes there; async producers are not changed. If two requests on a shared channel (`producerPoolEnabled=false`) add it at the same time, the second keeps the first one's handler. Not changed: with `producerPoolEnabled=false` and several requests in flight on the one channel (a correlation manager), the channel has one read timeout, and the reply to one request removes it for the others; that is how the read timeout works per channel, and the correlation managers have their own timeout. The 100-continue path (`CamelNettyClientContinue`) also returns after the timeout was removed. Model: `NettyRequestTimeout.tla` (the `timeout` handler across requests on one channel, for the pool, the singleton pool and reuseChannel): "a request that waits for its reply can time out" is violated on main for the singleton pool and reuseChannel (second request, 4 states) and holds for the pool; with the change it holds for all three. Tests: `NettyRequestTimeoutReusedChannelTest`: a server that answers "Hello Camel" late (it waits on a latch, at most 5 s); with `producerPoolEnabled=false` "Hello" then "Hello Camel" on the same endpoint, and a route that calls the endpoint twice with `reuseChannel=true`. On main both fail (the second request gets the late reply instead of a `ReadTimeoutException`); with the change both pass. camel-netty module tests: 164 run, 0 failures, 9 skipped. The new class 20 times in one JVM: 40 run, 0 failures (in a first series of 20, one run could not start the test's server route, `BindException: Address already in use` on the port the test picked, before any assertion; all other runs passed). `camel-netty-http` gets the same change, as `NettyHttpProducer` extends `NettyProducer` and its pipeline names the handlers `timeout` and `handler` too (`producerPoolEnabled=false` or `reuseChannel=true` there keep the request timeout as well): camel-netty-http module tests 383 run, 0 failures, 10 skipped. # 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): [CAMEL-27172](https://issues.apache.org/jira/browse/CAMEL-27172). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the touched modules with the formatter and import-sort plugins; no option, doc or generated file changes. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
