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

Sami Peltola commented on CAMEL-20563:
--------------------------------------

Attached an example project, instructions in the README.md.

Seems that using breakOnFirstError option for Kafka component creates a new 
heartbeat thread every time KafkaFetchRecords is set to reconnect, which 
happens when there an exception is allowed to propagate back from the route.

In KafkaFetchRecords, the task is set to reconnection state every time an 
exception bubbles back from the route:


{code:java}
                // when breakOnFirstError we want to unsubscribe from Kafka
                if (result != null && result.isBreakOnErrorHit() && 
!this.state.equals(State.PAUSED)) {
                    LOG.debug("We hit an error ... setting flags to force 
reconnect");
                    // force re-connect
                    setReconnect(true);
                    setConnected(false);
                }
{code}

This will lead to kafka-client 
*kafkaConsumer.getEndpoint().getKafkaClientFactory().getConsumer* being called 
again in KafkaFetchRecords.createConsumer(), which in turn creates 
ConsumerCoordinator again. The problem is that the heartbeat-thread created for 
the previous ConsumerCoordinator is never shutdown. 

The new ConsumerCoordinator will have class member heartbeatThread set to null 
and the next time ensureActiveGroup is called, a new heartbeat-thread is 
created:


{code:java}
    private synchronized void startHeartbeatThreadIfNeeded() {
        if (heartbeatThread == null) {
            heartbeatThread = new HeartbeatThread();
            heartbeatThread.start();
        }
    }
{code}




> camel-kafka - breakOnFirstError causes thread and memory leaks
> --------------------------------------------------------------
>
>                 Key: CAMEL-20563
>                 URL: https://issues.apache.org/jira/browse/CAMEL-20563
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-kafka
>    Affects Versions: 3.18.5, 3.22.1
>            Reporter: Aniket Jadhav
>            Priority: Major
>         Attachments: KafkaHeartBeatLeakThread.PNG, 
> heartbeat-threading-problem.zip
>
>
> This has got fixed in 
> [CAMEL-16857|https://issues.apache.org/jira/browse/CAMEL-16857]. But Facing 
> same issue with 3.18.5, is it reintroduced at some point? 
>  



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

Reply via email to