allthingssecurity commented on code in PR #26798:
URL: https://github.com/apache/camel/pull/26798#discussion_r4094284686
##########
components/camel-seda/src/main/java/org/apache/camel/component/seda/ThreadPerTaskSedaConsumer.java:
##########
@@ -128,9 +128,24 @@ protected void afterPollEmpty() {
@Override
protected void processPolledExchange(Exchange exchange) {
+ // count the task when it is dispatched (not when it starts running),
so a graceful shutdown
+ // also waits for polled exchanges whose task has not started yet
+ activeTasks.increment();
+ try {
+ dispatch(exchange);
+ } catch (RuntimeException e) {
+ // the task was not dispatched (e.g. rejected)
+ activeTasks.decrement();
Review Comment:
Good point. The undo is now in a `finally` block (in 435e03640), guarded by
a `dispatched` flag. That way it also covers an `Error` thrown while
dispatching, not only a `RuntimeException`.
A plain `finally` decrement wouldn't work here. The counter tracks tasks
that were dispatched but haven't finished, so on success the task decrements it
itself in its own `finally` when it completes. Decrementing again when
`dispatch` returns would count the task twice and let a graceful shutdown stop
waiting too early. So the `finally` only undoes the count when the task was
*not* dispatched. I also rebased onto current `main`. `Seda*` and
`*ThreadPerTask*`: 118 tests, 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]