[ 
https://issues.apache.org/jira/browse/CAMEL-23982?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-23982:
--------------------------------
    Fix Version/s: 4.22.0

> camel-yaml-dsl - shared bean cache cleared globally after each configure() 
> causes beans to be created twice when loading multiple YAML files
> --------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-23982
>                 URL: https://issues.apache.org/jira/browse/CAMEL-23982
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-yaml-dsl
>    Affects Versions: 4.21.0
>            Reporter: Federico Mariani
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.22.0
>
>
> {{BeansDeserializer}} keeps a {{beanCache}} ({{name:type}} keys) to avoid 
> creating beans twice: beans are created eagerly during pre-parse and the 
> {{beans}} node is constructed *again* during {{configure()}} (see comment at 
> {{BeansDeserializer.java:80-84}}). The deserializer instance is shared per 
> loader ({{YamlRoutesBuilderLoaderSupport.java:48}}), so the cache spans all 
> YAML resources.
> The problem: {{YamlRoutesBuilderLoader}}'s {{configure()}} ends with a 
> *global* {{beansDeserializer.clearCache()}} 
> ({{YamlRoutesBuilderLoader.java:174}}), but {{DefaultRoutesLoader}} 
> pre-parses *all* resources first ({{DefaultRoutesLoader.java:147-176}}) and 
> only then are builders configured one by one ({{RoutesConfigurer}}).
> Failure scenario with two files {{a.yaml}} and {{b.yaml}}, each containing a 
> {{beans:}} block:
> # pre-parse registers beans from both files and fills the cache;
> # {{configure()}} for {{a.yaml}} correctly skips its beans as duplicates, 
> then calls {{clearCache()}} wiping *all* keys including {{b.yaml}}'s;
> # {{configure()}} for {{b.yaml}} re-constructs its {{beans}} node, gets cache 
> misses, and *creates and rebinds every bean a second time* — 
> constructors/init-methods run twice, and the first instance is replaced in 
> the registry without its destroy-method being invoked (leaked resources, 
> duplicated side effects).
> Fix: clear only the keys belonging to the resource being configured (or key 
> the cache per resource) instead of {{beanCache.clear()}}.
> Related hardening in the same code path: the {{preparseDone.remove(...)}} + 
> {{clearCache()}} cleanup at {{YamlRoutesBuilderLoader.java:167-174}} is not 
> in a {{finally}} block, so an exception during {{configure()}} leaves stale 
> pre-parse state; on dev-mode reload of the corrected file, {{preParseRoute}} 
> short-circuits ({{:636-638}}) and edited {{beans}} definitions are silently 
> not re-parsed.
> _Filed by Claude Code on behalf of Croway._



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

Reply via email to