allthingssecurity opened a new pull request, #30626:
URL: https://github.com/apache/camel/pull/30626

   # Description
   
   [CAMEL-27330](https://issues.apache.org/jira/browse/CAMEL-27330)
   
   `maxConcurrentConsumers` of the MLLP consumer is documented as: "If a new 
connection is received and the maximum is number are already established, the 
new connection will be reset immediately." It no longer does that.
   
   Since 4.18, `MllpTcpServerConsumer.doStart` creates the consumer executor 
from a `ThreadPoolProfile` (CAMEL-22957, virtual threads support, moved the 
executors to the `ExecutorServiceManager`; its follow-up commit a47b4c7 "use 
SynchronousQueue to avoid acknowledgment timeouts" added the profile) with 
`poolSize=1`, `maxPoolSize=maxConcurrentConsumers` and `maxQueueSize=0`, and no 
rejected policy. `BaseExecutorServiceManager.newThreadPool` merges in the 
default profile, whose policy is `CallerRuns`. So when all the threads serve a 
connection, `submit` does not throw: the new connection's runnable runs on the 
calling thread, a thread of the (unbounded) validation pool. The reset in 
`startConsumer` (the `RejectedExecutionException` catch) is never reached, and 
every connection is served. Before 4.18 the executor was `new 
ThreadPoolExecutor(1, maxConcurrentConsumers, ..., new SynchronousQueue<>())`, 
with the JDK default `AbortPolicy`.
   
   `MllpMaxConcurrentConsumersTest.testConcurrentConsumersMoreThanMaxConsumers` 
did not catch this: its second client connected to a second free port, where 
nothing listens, so `connect()` failed for that reason.
   
   When a runnable is rejected, `startConsumer` also left it in 
`consumerRunnables`, with its closed socket and the buffer that holds the first 
message (the JMX view of the connections lists it too): only the runnable 
removes its entry when it ends, and a rejected runnable never runs. With the 
Abort policy this is the path of every rejected connection.
   
   This change (`MllpTcpServerConsumer`):
   
   - the consumer profile sets `ThreadPoolRejectedPolicy.Abort`, so a 
connection above the limit is reset again;
   - `startConsumer` removes a rejected runnable from `consumerRunnables`.
   
   With virtual threads enabled and `maxConcurrentConsumers` above 1, 
`DefaultThreadPoolFactory` creates a thread-per-task executor that has no 
limit; that is not changed here.
   
   Model: found with a TLA+ model of the MLLP consumer (accept, validation, 
consumer executor, stop and start). I extended it with the fix: on main the 
executor runs more consumers than the limit (CallerRuns), and with Abort a 
rejected runnable stays in the map. With the fix both hold, 3 connections, a 
limit of 2, 2 starts, lenient bind (511,135 distinct states; TLC and everystate 
agree).
   
   Tests: `MllpMaxConcurrentConsumersTest`:
   
   - `testConcurrentConsumersMoreThanMaxConsumers`: the second client now 
connects to the consumer's port. The connection is accepted by the operating 
system and then reset: sending a message gets no acknowledgement. The rejected 
connection is not kept in `consumerRunnables`.
   - new `testConnectionAfterTheOtherOneClosedIsServed`: once the first 
connection has ended, a new one is served (control, passes on main).
   
   On main the changed test fails (the second connection gets an `MSA|AA` 
acknowledgement); with only the policy changed and not the removal, it fails on 
the map check (the rejected runnable stays). With the change the unit tests of 
camel-mllp run 371 tests with 1 failure, in 
`MllpTcpServerConsumerThreadPoolTest` (100 messages through the MLLP producer 
with a 10 s wait each; disabled on CI as a slow test): no connection was 
rejected in that run (5 consumers started, none refused), and the test passed 6 
of 6 runs alone with the change. It is flaky on main too (it failed 1 of 4 runs 
on main in a later check, the same way: one of the 100 requests through the one 
producer connection waits longer than the test's 10 s). 
`MllpMaxConcurrentConsumersTest` 20 times in one JVM: 60 run, 0 failures.
   
   Upgrade guide: a 4.24 entry, as clients that open more connections than 
`maxConcurrentConsumers` (default 5) now get the extra ones reset. It says how 
to keep serving them (raise `maxConcurrentConsumers` to the number of 
connections the clients open). Users of 4.17 and older see no change: the limit 
applied there.
   
   # 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-27330](https://issues.apache.org/jira/browse/CAMEL-27330).
   
   # 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]

Reply via email to