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

Work on CAMEL-24267 started by Guillaume Nodet.
-----------------------------------------------
> ThrottlingInflightRoutePolicy.setResumePercentOfMax has writer-side race 
> condition
> ----------------------------------------------------------------------------------
>
>                 Key: CAMEL-24267
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24267
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Guillaume Nodet
>            Assignee: Guillaume Nodet
>            Priority: Major
>              Labels: good-first-issue
>
> Found during review of PR #24985 (CAMEL-24227: volatile sweep for 
> JMX-writable fields). The PR introduced {{ThrottlingLimits}} immutable holder 
> records to fix *reader-side* tearing, but *writer-side* atomicity remains 
> unaddressed.
> h3. Problem
> {{setResumePercentOfMax(int)}} reads {{this.maxInflightExchanges}} to compute 
> the resume value, then publishes a new {{ThrottlingLimits}} holder. Two 
> concurrent JMX writers calling {{setResumePercentOfMax}} and 
> {{setMaxInflightExchanges}} simultaneously can each read the other's stale 
> value, producing a holder built from a mixed snapshot.
> {code:java}
> public void setResumePercentOfMax(int resumePercentOfMax) {
>     this.resumePercentOfMax = resumePercentOfMax;
>     // reads maxInflightExchanges — but another writer may be changing it 
> concurrently
>     int resume = (int) (maxInflightExchanges * resumePercentOfMax / 100.0);
>     this.throttlingLimits = new ThrottlingLimits(maxInflightExchanges, 
> resume);
> }
> {code}
> h3. Suggested fix
> Synchronize the writer methods, or use a compare-and-swap loop on the 
> volatile holder reference to ensure the snapshot is consistent.
> h3. References
> * PR [#24985|https://github.com/apache/camel/pull/24985] review comment by 
> oscerd
> * 
> {{core/camel-core-processor/src/main/java/org/apache/camel/processor/ThrottlingInflightRoutePolicy.java}}



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

Reply via email to