allthingssecurity opened a new pull request, #30627: URL: https://github.com/apache/camel/pull/30627
# Description [CAMEL-27334](https://issues.apache.org/jira/browse/CAMEL-27334) `ClientChannelHandler.exceptionCaught` set `exceptionHandled = true` before it looked for the state of a request on the channel. When the channel has no state, it returned without closing the channel, and the flag is only reset in `channelActive`, which does not run again for that channel. The next request on the channel then never completed: - its `requestTimeout` fires: `exceptionCaught` returns at the flag check, the `ReadTimeoutHandler` closes the channel, and `channelInactive` skips the callback because of `!exceptionHandled`; - the server closes the connection without a reply: `channelInactive` skips the callback the same way. A channel has no state when it is in the producer pool and no request used it yet: with `lazyChannelCreation=false` the producer opens a channel at start and puts it in the pool unused, and the server can send it bytes the decoder rejects (for example a line longer than `decoderMaxLineLength`, `TooLongFrameException`). The model also found a narrower window: an exception that arrives between the borrow of a channel and `putState`. CAMEL-27173 handled the case of a done state (the channel is closed); the case of no state was left. This change (`ClientChannelHandler.exceptionCaught`): when there is no state, the exception is logged at DEBUG and the flag is not set; the flag is set only when a state was found (a done state closes the channel as before, a pending one fails the exchange and closes the channel as before). The channel stays in the pool, so the next request on it completes by its reply, its exception, its read timeout or the close of the channel. I did not close the channel here (as the done case does): with `producerPoolEnabled=false` and a correlation manager, many requests share the one channel, and closing it on any exception would change that mode. With a correlation manager that extends `TimeoutCorrelationManagerSupport`, `getState(ctx, channel, cause)` always returns `null`, and `channelInactive` gets no state from it either, so the flag had no effect there; nothing changes for it except the DEBUG log. Model: found with a TLA+ model of the netty producer (pool, correlation manager, reply, read timeout, server close, write failure, stop). The audit had stray exceptions off in its passing runs. I turned them on and added the fix: on main an exchange is stuck (deadlock) after a read timeout and is still pending after a stop; with the fix no exchange is stuck and the other invariants (callback at most once, no reply to another exchange, no leaked borrow, nothing pending after stop) hold, both for the idle channel and for the borrow/putState window: 3 exchanges, 4 channels, 1 stray exception, 2,667,058 distinct states (TLC and everystate agree). Tests: new `NettyProducerStrayExceptionTest` (a plain `ServerSocket` server that greets the channel opened at start; a probe handler before the producer's handler tells the test when the exception was handled): - the greeting is too long for the decoder, then the request is not answered (requestTimeout 1 s): the exchange must complete with `ReadTimeoutException`; - the greeting is too long, then the server closes the connection after the request: the exchange must complete with "No response received from remote server"; - the server sends nothing before the request, which is not answered: completes with `ReadTimeoutException` (control, passes on main). On main the first two fail (the exchange is not completed 10 s after the request); the control passes. With the change the unit tests of camel-netty run 169 tests: 1 failure, in a first version of the control whose short greeting could arrive after the request and be taken as its reply (fixed, the control now sends nothing); the three pass after that. The new class 20 times in one JVM: 60 run, 0 failures. The test waits until the producer's channel group holds the channel opened at start (a listener of the connect future adds it on the event loop, which can run just after the start returned). # 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-27334](https://issues.apache.org/jira/browse/CAMEL-27334). # 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 and tested the affected modules, including the formatter and import-sort plugins. 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]
