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

   Thanks @davsclaus, you are right: the status check refused exactly the 
inflight exchanges the shutdown strategy waits for. Pushed bd10114b3664 on top 
of your rebase:
   
   1. **No refusal while the CamelContext is `Stopping`**: done as you 
suggested. The context plugin (`ExecutorServices`) now extends 
`LifecycleStrategySupport` and is added with 
`context.addLifecycleStrategy(...)` when it is created. It holds a volatile 
`closed` flag, set in `onContextStopped` and cleared in `onContextStarting`; 
both take the lock of the lookup, so a pool is either created before `closed` 
is set (and then shut down by the `ExecutorServiceManager`, which runs later in 
`doStop`) or not at all. The lookup throws `RejectedExecutionException` only 
when `closed` is set, and the check after the `submit` still covers a pool shut 
down meanwhile. `ServiceStatus` is no longer read, so NEW/BUILT no longer count 
as stopped.
      Tests (`AbstractApiProducerRejectedCallTest`):
      - `testFirstCallOfAnInflightExchangeWhileTheCamelContextStopsCompletes`: 
an exchange waits in a step before the API endpoint (no pool yet), 
`context.stop()` starts on another thread, and once the status is `Stopping` 
the exchange goes on and makes its first API call: it gets a pool and completes 
with the reply;
      - `testCallBeforeTheCamelContextStartedCompletes`: a producer used before 
its CamelContext started gets a pool and completes; that pool is shut down when 
the CamelContext is started and stopped;
      - `testCallAfterTheCamelContextStartedAgainCompletes`: after a stop and a 
start the endpoint gets a new pool (the flag is cleared again).
      The two existing tests (a call racing the stop, a call after the stop) 
still pass unchanged. On the previous head of this PR the first two new tests 
fail with `RejectedExecutionException` ("CamelContext ... is Stopping/Stopped, 
no thread pool is created"); now all five pass.
   
      About #29999: this changes code from #29999 (the plugin class and where 
it is created). I made the change only in this follow-up commit on #30000 and 
did not push to #29999, which you approved as it is.
   
      One case is left as before: a pool asked for the first time in this 
CamelContext after `onContextStopped` (no route runs then) is still created, 
since the plugin, and so the flag, does not exist yet.
   
   Tests on the new head: the `org.apache.camel.support` tests and the thread 
pool, executor service and lifecycle strategy tests of camel-core (717 run, 0 
failures, 2 skipped), and the tests of camel-support (169, 0 failures) and 
camel-util (19, 0 failures).
   
   _Claude Code on behalf of allthingssecurity_
   


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