dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.01k forks source link

Exceptions from IHubActivator.Create are not being propagated to SignalR Client #58749

Open vsfeedback opened 15 hours ago

vsfeedback commented 15 hours ago

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version] Issue Summary:

I have a SignalR server project which implements the Create method from the Microsoft.AspNet.SignalR.IHubActivator interface.

If an exception occurs in this Create method, I do not receive the corresponding exception on the client side. In other cases, when exceptions occur on the server side, they are propagated to the client so I can handle them appropriately, but not in this case.

Here is a simple chat application which demonstrates the issue: SignalRSelfHost.zip

This is based on the SignalR Self-Host tutorial here.

In the server portion of the application (SignalRSelfHost.csproj) I throw an exception in my IHubActivator implementation as shown below:

image.png

In the client project (JavascriptClient) I have an error handler which should be called whenever an error occurs when calling the only method on the SignalR hub, as shown below:

image.png

But when I run the project, no exception appears in the console window of the browser.

Questions:

  1. Is there any way I can ensure that the client receives exceptions that are thrown in the IHubActivator.Create method?

  2. If I am unable to propagate exceptions from the IHubActivator.Create method, my backup plan is to just return null whenever an exception occurs in IHubActivator.Create, since this does produce an exception on the client side. This way I can just output a generic message such as "Error occurred when creating SignalR Hub". Would you see any issue with handling IHubActivator.Create exceptions in this way?

Reproduction Steps:

Perform the following steps to reproduce the issue:

  1. Download the attached zip folder and extract the SignalRSelfHost solution.
  2. Build and run the solution. Both the Chat App and Server should run.
  3. Open the developer console window in the Chat App window.
  4. Send a test message through the Chat app.
  5. Notice that no message appears in the console window even though an exception occured.

Original Comments

Feedback Bot on 10/28/2024, 06:37 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

BrennanConroy commented 15 hours ago

Exceptions are not exposed to the user by default to avoid leaking information. https://learn.microsoft.com/aspnet/core/signalr/security?view=aspnetcore-8.0#exceptions

If you are explicitly throwing an error that you are ok with the client seeing, then you can throw a HubException. https://learn.microsoft.com/aspnet/core/signalr/hubs?view=aspnetcore-8.0#handle-errors