You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Petr Holubec (Jira)" <ji...@apache.org> on 2022/11/11 11:42:00 UTC
[jira] [Created] (CAMEL-18713) Loop processor interrupted when Camel engine shutdown
Petr Holubec created CAMEL-18713:
------------------------------------
Summary: Loop processor interrupted when Camel engine shutdown
Key: CAMEL-18713
URL: https://issues.apache.org/jira/browse/CAMEL-18713
Project: Camel
Issue Type: Bug
Components: camel-core
Affects Versions: 3.18.2, 3.14.6, 3.14.4
Environment: * occurred on Windows 11
* tried with Camel versions {{{}3.14.4{}}}, {{3.14.6}} and {{3.18.2}}
* route starts using {{{}scheduler://{}}}{{{}{}}}
Reporter: Petr Holubec
*Description*
I have a route constructed approximately like this:
{code:java}
processDefinition
.process { ex -> // setup repeating }
.loopDoWhile(RepeatingPredicate())
.process { ex -> // prepare iteration }
.process { ex -> // do work }
.process { ex -> // finish iteration }
.end()
.process { ex -> // clean up repeating }
{code}
The route does some setup and then starts iterating - let's say 10 iterations when "the work" takes 10 seconds to complete.
Then, in the middle of processing (let's say during 5th iteration), I request Camel engine to shutdown with infinite timeout:
{code:java}
context.shutdownStrategy.timeout = Long.MAX_VALUE
context.stop(){code}
But the Camel engine will shutdown immediately because it is not able to correctly detect current inflight requests.
*Additional Info*
More specifically, the {{ShutdownTask}} class tries to [get inflight requests|[https://github.com/apache/camel/blob/ca8b653c50b0ee32a522455635fbc4c7564c5972/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java#L674|https://github.com/apache/camel/blob/ca8b653c50b0ee32a522455635fbc4c7564c5972/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java#L674):]]:
* _InflightRepository_ returns 1 which is correct number
* but iterating over services returns negative number at the end
-> so the condition {{size > 0}} is false which means no inflight requests
When going deeper, the {{LoopProcessor}} classes are the ones which return negative numbers of inflight requests.
Looks like the {{taskCount}} is not initialized because[ {{expression}} is null|[https://github.com/apache/camel/blob/fb44d321a0dd0e5190565f0bb15e73fc0f14ef3d/core/camel-core-processor/src/main/java/org/apache/camel/processor/LoopProcessor.java#L127]] which means it's value is 0 but [decremented several times|[https://github.com/apache/camel/blob/fb44d321a0dd0e5190565f0bb15e73fc0f14ef3d/core/camel-core-processor/src/main/java/org/apache/camel/processor/LoopProcessor.java#L153]]
which will cause negative numbers to return.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)