allthingssecurity commented on PR #30704:
URL: https://github.com/apache/camel/pull/30704#issuecomment-7125444523

   Thanks Claus, good catches, both of the first two were real. Everything is 
in one new commit: f6cb19b32a.
   
   1. Restart during the validation read: `validateConsumer` now takes the 
consumer executor of its start and hands it to the validation runnable (a new 
`TcpServerConsumerValidationRunnable` constructor; the old one stays and uses 
the consumer's current executor). The runnable calls a new 
`startConsumer(Socket, MllpSocketBuffer, ExecutorService)`, which submits to 
that executor; the old two-argument `startConsumer` delegates with the current 
one. After a stop that executor is shut down, so the submit is rejected and the 
socket reset (logged at debug, not as "max consumers already active"). New test 
`testConnectionValidatedDuringRestartIsNotServedAfterRestart`: the consumer 
stops and starts again while the connection is held after its validation read; 
then no consumer runnable runs for it, a new connection is served and the old 
one gets no answer. When the submit goes to the current executor instead, it 
fails (the old connection is served).
   
   2. `doShutdown` now calls `consumerExecutor.shutdownNow()` and 
`validationExecutor.shutdownNow()` directly, after the manager's `shutdownNow` 
(which only unregisters them now). New test 
`testShutdownInterruptsTheRunnableServingAConnection`: the processor sleeps 
while it serves a message, the consumer stops and shuts down, and the processor 
must be interrupted within 5 seconds. Without the direct call it is not. The 
test runs on platform threads, as the virtual threads switch is JVM wide 
(`ThreadType` caches it), so it checks the interrupt itself rather than the 
socket close you get with virtual threads.
   
   3. `TcpSocketConsumerRunnable.run()` now returns at the top of the try block 
when `running` is false, so a runnable stopped between the check and the submit 
does not send the messages of the validation read to the stopping route. The 
finally block still removes it and resets the socket. No separate test for this 
one: the window is between two lines of `startConsumer`, and I did not find a 
way to hold it there without a hook in production code.
   
   4. `connectAndStopDuringValidation` is gone. The stop test now builds the 
consumer itself, like the lenient-bind test, with a subclass that holds a 
connection in `startConsumer` (after its validation read ended) until the test 
releases it. The tests stop, or stop and start, the consumer in between, so 
nothing depends on landing inside the 500 ms read. In one module run an await 
of the new lenient-bind test failed on an uncaught exception of an accept 
thread that test had no connection for, most likely one of another test (the 
module's tests run in parallel, and Awaitility catches uncaught exceptions of 
every thread by default). The awaits of both classes now use 
`dontCatchUncaughtExceptions()`.
   
   5. Owner check: done, it was small. `bindThread` is set in `doStart` and 
cleared in `doStop` under `acceptThreadLock`, and the bind thread calls a new 
`startAcceptThread(ServerSocket, TcpServerBindThread owner)`, which closes the 
socket when the caller is not the bind thread of the current start. The 
one-argument method stays and only checks the state. New test 
`testBindOfPreviousStartCompletingAfterRestartDoesNotStartAcceptThread`: the 
bind of the first start completes after a stop and start; its socket must be 
closed, and the bind thread of the new start then binds the port and runs the 
only accept thread. Without the owner check the old socket stays open and its 
accept thread runs.
   
   One smaller window I did not close here: an accept thread of the previous 
start that only calls `validateConsumer` after a restart would still pick up 
the new start's executor. It needs the old accept loop to survive the stop and 
the restart, which the owner check and the stop's socket close make narrow, so 
I left it as a possible follow-up.
   
   Runs: camel-mllp unit tests 388 run, 0 failures, 3 skipped. 
`MllpTcpServerConsumerStopTest` and `MllpTcpServerConsumerLenientBindStopTest` 
20 times in one JVM: 160 run, 0 failures. Each of the three new tests fails 
with its change taken out, and the other tests of the two classes still pass 
then. Formatter and import sort pass. The PR merges cleanly with the current 
main.
   


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