Skip to content

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

Merged
kabir merged 2 commits into
a2aproject:mainfrom
ehsavoie:issue_946
Jun 29, 2026
Merged

kabir merged 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.

@ehsavoie
ehsavoie force-pushed the issue_946 branch 3 times, most recently from 9803e94 to 3a295b3 Compare June 25, 2026 15:51
@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.

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 <[email protected]>
@kabir

kabir commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

/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. In JdkA2AHttpClient, CancellationException is now ignored in both onError and the CompletableFuture handler to prevent spurious errors from being propagated to the error consumer, backed by new unit tests. In MultiVersionJSONRPCRoutes and MultiVersionRestRoutes, CDI request context destruction is now deferred for streaming endpoints using runInRequestContextDeferred. Additionally, MultiInstanceReplicationTest was updated to check for the initial task receipt instead of a simple event count. The reviewer recommended unwrapping the throwable's cause in onError before checking for CancellationException to ensure wrapped exceptions are also correctly ignored, matching the logic used in the CompletableFuture handler.

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.

…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 <[email protected]>
@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 updates multi-version REST and JSON-RPC routes to defer CDI request context destruction for streaming endpoints. It also modifies the HTTP client to prevent CancellationExceptions from being propagated to the error consumer, accompanied by new unit tests, and refactors a multi-instance replication test to wait for initial task events. Feedback is provided to limit the traversal depth of exception causes in the new isCancellation helper to avoid potential infinite loops from cyclic exception chains.

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.

@kabir
kabir merged commit 4d746aa into a2aproject:main Jun 29, 2026
12 checks passed
@ehsavoie
ehsavoie deleted the issue_946 branch July 28, 2026 12:36
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

2 participants