Skip to content

Add SignalR client log for stream item binding failure #60857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

BrennanConroy
Copy link
Member

Fixes #56303

Turns out the Java client didn't even handle stream binding failures and just closed the connection, so added support for that.

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Mar 10, 2025
@BrennanConroy BrennanConroy requested a review from halter73 as a code owner March 10, 2025 20:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR adds logging support for stream item binding failures in the SignalR Java and C# clients to address an issue where the Java client closed the connection without handling such errors.

  • Added tests to validate stream item binding failure handling in both Java and C# clients.
  • Updated protocol and connection handling logic to log binding exceptions in streams.
  • Introduced a new logger message and error handling case for stream binding failures in the core client code.

Reviewed Changes

File Description
src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/HubConnectionTest.java Added test to verify logging of stream binding failures.
src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Protocol.cs New test verifies that stream binding errors are logged and the connection remains active.
src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java Adjusted result parsing to catch binding exceptions and convert them into stream binding failure messages.
src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs Added a new case to handle StreamBindingFailureMessage and log the error accordingly.
src/SignalR/clients/csharp/Client.Core/src/HubConnection.Log.cs Added a logger definition for stream binding failures.
src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java Introduced a new case in the receive loop for stream binding failures with proper logging.

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM overall -- is this a backport candidate or nah?

try {
result = gson.fromJson(reader, binder.getReturnType(invocationId));
} catch (Exception ex) {
argumentBindingException = ex;
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a way of capturing the value that failed to bind here? If so, that might be helpful to capture in the exception. Ditto with the streamToken below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Relying on the underlying json library to provide the error, in the case of the test I added the error would contain: java.lang.NumberFormatException: For input string: "str"

if (invocationId == null || binder.getReturnType(invocationId) == null) {
resultToken = JsonParser.parseReader(reader);
} else {
result = gson.fromJson(reader, binder.getReturnType(invocationId));
}
break;
case "item":
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we don't need to set the same guards when we're parsing properties from the result key?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason is that it's a different bug/improvement and I don't want to pollute this PR 😆

@@ -10,11 +10,10 @@ dependencies {
implementation 'org.junit.jupiter:junit-jupiter-params:5.11.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.code.gson:gson:2.8.9'
Copy link
Member

Choose a reason for hiding this comment

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

Is this bump related to the fix or just for good measure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't have been needed, but for some reason when debugging the test in VS Code it complained about a method not being found in gson, command line passed just fine. So I updated the dep and VS Code started working 🤷

Copy link
Member

@DeagleGross DeagleGross left a comment

Choose a reason for hiding this comment

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

agree with Safia's comments, but overall LGTM

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 18, 2025
@BrennanConroy
Copy link
Member Author

/azp run

@BrennanConroy BrennanConroy removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 18, 2025
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@BrennanConroy BrennanConroy merged commit 04ed093 into main Mar 18, 2025
27 checks passed
@BrennanConroy BrennanConroy deleted the brecon/streambinderror branch March 18, 2025 21:53
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview3 milestone Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SignalR eats JSON serialization exceptions during streaming responses
3 participants