[
https://issues.apache.org/jira/browse/CAMEL-24144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen reassigned CAMEL-24144:
-----------------------------------
Assignee: Claus Ibsen
> camel-saga: InMemorySagaService never removes coordinators - unbounded memory
> growth
> ------------------------------------------------------------------------------------
>
> Key: CAMEL-24144
> URL: https://issues.apache.org/jira/browse/CAMEL-24144
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Reporter: Federico Mariani
> Assignee: Claus Ibsen
> Priority: Major
>
> h3. Problem
> {{InMemorySagaService.newSaga()}}
> (core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaService.java:54)
> puts every new coordinator into the {{coordinators}} map:
> {code:java}
> CamelSagaCoordinator coordinator = new InMemorySagaCoordinator(camelContext,
> this, uuid);
> coordinators.put(uuid, coordinator);
> {code}
> Nothing ever removes entries from that map - not on {{complete()}}, not on
> {{compensate()}}, not on timeout. Each {{InMemorySagaCoordinator}} retains
> its step list and all evaluated option values.
> h3. Consequence
> Any long-running application using the in-memory saga service grows without
> bound: one map entry plus coordinator state per saga, forever.
> A secondary effect is that {{getSaga(id)}} happily returns finished
> coordinators, so a stale {{Long-Running-Action}} header can re-join a saga
> that already compensated (it then fails at {{beginStep}} with
> {{IllegalStateException}}).
> h3. Suggested fix
> Remove the coordinator from the map when it reaches a terminal state
> (COMPENSATED/COMPLETED), e.g. via a callback from the coordinator to the
> service. Note the removal must be deferred until the finalization chain
> actually finishes, since {{doCompensate()}}/{{doComplete()}} run
> asynchronously on the saga executor.
> Found during a broader Saga EIP / camel-lra code review (July 2026).
> _Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)