CAMEL-23945: Fix producer race on shared agent field (backport to 4.18.x) - #25063
Merged
davsclaus merged 1 commit intoJul 24, 2026
Merged
Conversation
…on test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
davsclaus
approved these changes
Jul 24, 2026
davsclaus
marked this pull request as ready for review
July 24, 2026 06:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Code on behalf of gnodet
Summary
Backport of the fix for CAMEL-23945 to the
camel-4.18.xbranch.On
main, the race condition inLangChain4jAgentProducer.process()was inadvertently fixed by commit03d8361bbb7(CAMEL-23697), which refactored the method to use a local variable. Oncamel-4.18.x, the original race still exists:agentFactory.createAgent(exchange)writes to the sharedthis.agentinstance field, so concurrent exchanges can see each other's agents.The race (before this PR)
Between the write and the read, another thread can overwrite
this.agentwith a different exchange's agent, causing the first exchange to use the wrong agent.The fix
A method-local variable ensures each exchange uses only its own factory-created agent.
Changes
LangChain4jAgentProducer.java: Changedprocess()to use a localAgent agentvariable instead of writing to the shared instance fieldLangChain4jAgentProducerConcurrencyTest.java: Added regression test that sends 50 concurrent exchanges through a single producer endpoint, each with a distinct factory-created agent. Verifies that every exchange receives the response from its own agent, not from another exchange's agent.Test plan
LangChain4jAgentProducerConcurrencyTestpasses (1 test)🤖 Generated with Claude Code