[ 
https://issues.apache.org/jira/browse/CAMEL-23030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18059549#comment-18059549
 ] 

Andrea Evangelista commented on CAMEL-23030:
--------------------------------------------

Hi guys I'm experiencing the same issue (camel 4.14.1)



The {{StackOverflowError}} is caused by the {{AggregateProcessor}} executing 
its completion logic recursively on the same thread.
 
{code:java}
aggregateDefinition.executorService(new SynchronousExecutorService());{code}
{{ }}
This is the root of the problem.
h3. What Happens Internally (at least what I saw till now)

When an aggregation completes (due to {{completionSize}} or 
{{{}completionTimeout{}}}), Camel invokes:
 
{code:java}
AggregateProcessor.onSubmitCompletion(...){code}
{{ }}
Normally, this completion task is submitted to a thread pool. That allows:
 * The current call stack to unwind

 * The completion logic to execute asynchronously

 * No recursive stack growth

However, {{SynchronousExecutorService}} does not schedule work on another 
thread. Instead, it executes the task immediately on the same thread:
 
{code:java}
execute(task) { task.run(); // runs inline }{code}
{{ }}
As a result, each aggregation completion reenters the {{AggregateProcessor}} 
without unwinding the current stack.

The call stack effectively grows like this:
 
{{AggregateProcessor  → onSubmitCompletion
      → execute (same thread)
          → AggregateProcessor
              → onSubmitCompletion
                  → execute (same thread)
                      → AggregateProcessor
                          ...}}
If multiple aggregations complete in sequence , this process repeats 
continuously on the same thread, causing the stack to grow until it exceeds the 
JVM stack limit.

At that point, the JVM throws:
 
{{java.lang.StackOverflowError}}



{code:java}
at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.lambda$doRun$0(RedeliveryErrorHandler.java:782)
        at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:428)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:363)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.process(AggregateProcessor.java:319)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:777)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:720)
   at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.doRun(DefaultReactiveExecutor.java:199)
  at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeReactiveWork(DefaultReactiveExecutor.java:189)
    at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.tryExecuteReactiveWork(DefaultReactiveExecutor.java:166)
 at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
       at 
org.apache.camel.impl.engine.DefaultReactiveExecutor.schedule(DefaultReactiveExecutor.java:54)
       at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.lambda$doRun$0(RedeliveryErrorHandler.java:782)
        at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:428)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:363)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.process(AggregateProcessor.java:319)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:777)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:720)
   at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.doRun(DefaultReactiveExecutor.java:199)
  at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeReactiveWork(DefaultReactiveExecutor.java:189)
    at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.tryExecuteReactiveWork(DefaultReactiveExecutor.java:166)
 at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
       at 
org.apache.camel.impl.engine.DefaultReactiveExecutor.schedule(DefaultReactiveExecutor.java:54)
       at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.lambda$doRun$0(RedeliveryErrorHandler.java:782)
        at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:428)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:363)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.process(AggregateProcessor.java:319)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:777)
 at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:720)
   at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.doRun(DefaultReactiveExecutor.java:199)
  at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeReactiveWork(DefaultReactiveExecutor.java:189)
    at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.tryExecuteReactiveWork(DefaultReactiveExecutor.java:166)
 at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
       at 
org.apache.camel.impl.engine.DefaultReactiveExecutor.schedule(DefaultReactiveExecutor.java:54)
       at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.lambda$doRun$0(RedeliveryErrorHandler.java:782)
        at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:428)
       at 
org.apache.camel.processor.aggregate.AggregateProcessor.doProcess(AggregateProcessor.java:363)................................
 {code}
{{ Thanks a lot}}
h3.  

> Streaming splitter with aggregation results in StackOverflowError  
> -------------------------------------------------------------------
>
>                 Key: CAMEL-23030
>                 URL: https://issues.apache.org/jira/browse/CAMEL-23030
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 4.7.0
>         Environment: This issues occurs with any JVM version I have tried 
> (17, 21, 24) and it occurs on my Mac OS developer machine as well as a linux 
> vm that runs unit tests.
>            Reporter: Michael Parmeley
>            Priority: Minor
>         Attachments: 
> camel-synchronous-executor-stackoverflow-reproducer.tar.gz
>
>
> We have some routes with a streaming splitter that uses aggregation to group 
> file rows into batches of rows that throws a StackOverflowError on versions 
> of Camel > 4.6.
> I have attached a project with a single unit test in it that recreates the 
> problem. Steps to recreate:
> 1. Extract the attached project: tar xvfz 
> camel-synchronous-executor-stackoverflow-reproducer.tar.gz
> 2. Navigate into the created directory: cd 
> camel-synchronous-executor-stackoverflow-reproducer
> 3. Execute: ./gradlew test
> It comes "out-of-the-box" running with camel 4.17 and it will throw a 
> StackOverFlow error.
> To test against other versions edit `build.gradle` and uncomment/comment the 
> appropriate `camelVersion` declaration. The build.gradle file has comments 
> regarding versions that fail and pass. Although it is any version > 4.6 that 
> fail.
> I looked at the source for AggregationProcessor::onSubmitCompletion() and I 
> do see a difference on how the task is scheduled at the end between 4.6 and 
> 4.7.
> 4.6:
> {code:java}
>  reactiveExecutor.schedule(task);
> {code}
> 4.7:
> {code:java}
>  reactiveExecutor.scheduleSync(task);
> {code}
> It changes further in 4.8 to this:
> {code:java}
>     if (exchange.isTransacted()) {
>                 reactiveExecutor.scheduleQueue(task);
>             } else {
>                 reactiveExecutor.scheduleSync(task);
>             }
> {code}
> I ran my unit test against the very recently released 4.18 and the test still 
> results in a StackOverFlow error.
> Issue https://issues.apache.org/jira/browse/CAMEL-22147 seems similiar 
> although the fix made for that did not fix the issue we are having.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to