[
https://issues.apache.org/jira/browse/CAMEL-25620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18127064#comment-18127064
]
Claus Ibsen commented on CAMEL-25620:
-------------------------------------
Backported to camel-4.22.x in https://github.com/apache/camel/pull/27808
_Claude Code on behalf of
> camel-console: ConcurrentModificationException in
> DefaultDevConsoleRegistry.doStart when camel-cli-connector is enabled
> -----------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-25620
> URL: https://issues.apache.org/jira/browse/CAMEL-25620
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Reporter: James Netherton
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.22.2, 4.24.0
>
>
> h3. Problem
> {{DefaultDevConsoleRegistry}} stores its consoles in a {{TreeSet}} with no
> synchronisation. {{doStart()}} iterates the set to start each console, while
> {{register()}} adds to it. {{resolveById()}} calls {{register()}} when it
> resolves a console that is not yet in the set.
> When {{camel-cli-connector}} is enabled, the connector schedules its task
> with an initial delay of 0:
> {code:java}
> scheduledFuture = executor.scheduleWithFixedDelay(this::task, 0, delay,
> TimeUnit.MILLISECONDS);
> {code}
> That task calls {{DevConsoleRegistry.resolveById(...)}} for several consoles.
> If it runs while the CamelContext is still starting the registry, the
> iteration in {{doStart()}} fails and the CamelContext does not start:
> {noformat}
> ERROR [org.apache.camel.impl.engine.AbstractCamelContext] Error starting
> CamelContext (camel-2) due to exception thrown: null:
> java.util.ConcurrentModificationException
> at
> java.base/java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1522)
> at java.base/java.util.TreeMap$KeyIterator.next(TreeMap.java:1576)
> at
> org.apache.camel.impl.console.DefaultDevConsoleRegistry.doStart(DefaultDevConsoleRegistry.java:104)
> at
> org.apache.camel.support.service.BaseService.start(BaseService.java:132)
> at
> org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:129)
> at
> org.apache.camel.impl.engine.DeferServiceStartupListener.doStart(DeferServiceStartupListener.java:63)
> at
> org.apache.camel.impl.engine.DeferServiceStartupListener.onCamelContextStarting(DeferServiceStartupListener.java:49)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3152)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2841)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2796)
> at
> org.apache.camel.support.service.BaseService.start(BaseService.java:132)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2375)
> at
> org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:214)
> {noformat}
> The failure is intermittent because it depends on thread timing.
> h3. Proposed fix
> Make the registry safe for concurrent registration. For example:
> * use a concurrent sorted set ({{{}ConcurrentSkipListSet{}}}) for
> {{{}consoles{}}}, or
> * synchronise {{{}register(){}}}, {{{}doStart(){}}}, {{doStop()}} and the
> other methods that iterate {{{}consoles{}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)