Skip to content

fix: suppress CancellationException in JDK HTTP client SSE streaming#951

Open
ehsavoie wants to merge 2 commits into
a2aproject:mainfrom
ehsavoie:issue_946
Open

fix: suppress CancellationException in JDK HTTP client SSE streaming#951
ehsavoie wants to merge 2 commits into
a2aproject:mainfrom
ehsavoie:issue_946

Conversation

@ehsavoie

Copy link
Copy Markdown
Collaborator

Filter out CancellationException in both the reactive subscriber's onError and the CompletableFuture error handler to prevent spurious error propagation when the HTTP client is closed during an active SSE stream. Also fix a race between onError and onComplete by using compareAndSet in onComplete, and remove redundant subscription.cancel() calls.

This fixes #946 🦕

@ehsavoie ehsavoie requested a review from kabir June 25, 2026 11:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies JdkA2AHttpClient to prevent CancellationException from being propagated to the error consumer during asynchronous SSE stream processing. It updates the error handling logic in both the subscriber's onError method and the future's completion handler to filter out CancellationException. Additionally, it removes redundant subscription cancellation calls and adds comprehensive unit tests to verify this behavior. There are no review comments, so no further feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Filter out CancellationException in both the reactive subscriber's
onError and the CompletableFuture error handler to prevent spurious
error propagation when the HTTP client is closed during an active SSE
stream. Also fix a race between onError and onComplete by using
compareAndSet in onComplete, and remove redundant subscription.cancel()
calls.

This fixes a2aproject#946

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie ehsavoie force-pushed the issue_946 branch 2 times, most recently from db53b2b to 9803e94 Compare June 25, 2026 14:15
…endpoints

Streaming endpoints in MultiVersionJSONRPCRoutes and MultiVersionRestRoutes
were using runInRequestContext() which destroys the CDI context immediately,
before the async agent thread can access @RequestScoped beans. Switch to
runInRequestContextDeferred() which defers destruction until the SSE response
completes.

Also refactors MultiVersionRestRoutes to deduplicate dispatch methods by
adding a boolean streaming parameter and a runInContext() helper.

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several improvements and bug fixes across different modules. In the HTTP client, it prevents CancellationException from being propagated to the error consumer during asynchronous SSE operations and ensures thread-safe state transitions in onComplete. Corresponding unit tests have been added to verify this behavior. In the multi-version JSON-RPC and REST routing components, the request context handling has been updated to support deferred CDI context destruction for streaming endpoints. Finally, the multi-instance replication test was updated to use a more robust condition for verifying subscription establishment. No review comments were provided, and I have no additional feedback to offer.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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.

[QUESTION] Exception is thrown when using A2A client

1 participant