Skip to content

CAMEL-24811: camel-servlet - fix async servlet completing before the route finishes (backport 4.14.x) - #26598

Closed
Croway wants to merge 1 commit into
apache:camel-4.14.xfrom
Croway:CAMEL-24811-servlet-async-race-4.14.x
Closed

Croway wants to merge 1 commit into
apache:camel-4.14.xfrom
Croway:CAMEL-24811-servlet-async-race-4.14.x

Conversation

@Croway

@Croway Croway commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Backport of #26584 to camel-4.14.x (straight cherry-pick, no conflicts).

Fixes CAMEL-24811: CamelServlet.doServiceAsync() (async=true without executorRef, and camel-jetty with async=true&useContinuation=false) completed the AsyncContext before a route that resumes on another thread had written its response. The bug dates from CAMEL-11731 (Camel 3.7), so every LTS branch is affected.

No API changes: doService() keeps its signature, the in-flight stage is handed over via a protected request attribute constant. No upgrade guide entry needed.

Draft until #26584 is reviewed and merged on main.

Claude Code on behalf of Croway

…route finishes

CamelServlet.doServiceAsync() (async=true without executorRef) completed the
AsyncContext right after doService() returned, discarding the CompletionStage
that doExecute() returns when the route continues on another thread. This
races the container's async completion against the later writeResponse(),
giving an IllegalStateException on the recycled response (Tomcat) or an
empty/stale response. camel-jetty in async mode (async=true&useContinuation=false)
hits the same path via super.doService().

doService() keeps its void signature (protected extension point, must stay
binary compatible for backports); the in-flight stage is handed over via the
CamelAsyncPromise request attribute and doServiceAsync() completes the
AsyncContext only once it is done, mirroring doAsyncExecution().

Also: complete the AsyncContext in doAsyncExecution()'s error branch (onError
always throws), and always write the response / finish the UoW when
processAsync() fails synchronously or completes exceptionally.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Croway Croway closed this Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant