OnConnectedAsync and OnDisconnectedAsync are not invoked when a client application attempts to establish signalR connection

See original GitHub issue

Describe the bug

Create a signalR server application, derive a class from Hub class and override OnConnectedAsync and OnDisconnectedAsync in the derived class. Log some distinctive texts upon raising either of those events to ensure that you can track when they are raised. When a signalR client application like an angular application attempts to establish a connection, OnConnectedAsync may not raise in signalR server’s side. If that happens, OnDisconnectedAsync won’t raise too at disconnection attempt. This issue is intermittent but it happens noticeably. This issue’s frequency increases when the singalR server is using Azure’s SignalR Services.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 2.2.
  2. Follow the instructions above to setup a client and server application. Try both C# client and angular client applications.

Expected behavior

OnConnectedAsync and OnDisconnectedAsync events should be raised consistently upon establishing or disconnecting connections.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:32 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Arash-Sabetcommented, Feb 13, 2019

Not sharing the same Azure SignalR Service instance between two hubs resolved the issue.

1reaction
Arash-Sabetcommented, Jan 25, 2019

You guys are showing two different issues. If you are seeing an unexpected failure with: 'Error: Server returned an error on close: Internal server error. then please open a separate issue with details about that.

Lets keep this issue to the lack of OnConnectedAsync being called even though the connection was connected.

@Arash-Sabet In #6448 (comment) you showed the client connected and claim the OnConnectedAsync function wasn’t called. Could you try to get the same thing to happen and include the client logs starting with “Starting HubConnection.”

I know you can’t show us your OnConnectedAsync but can you confirm that you have a log statement in it and that the server logs do not show that log statement when the connection successfully connects.

@BrennanConroy I opened a separate issue to report type 7 issue. The issue is found here: https://github.com/aspnet/AspNetCore/issues/7020

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR Hub OnDisconnectedAsync Method Does Not Get ...
Here I am trying to remove ConnectionId from connected connectedId list UserHandler.ConnectedUser in OnDisconnectedAsync method of my hub. But ...
Read more >
Calling any function on ondisconnectedasync task in ...
Think about what you're asking. When a client disconnects from your hub, and will no longer receive any messages from your server.
Read more >
ASP.NET Core 3.1 SignalR Configuration, The Errors We ...
This Hub allows us to override two OnConnectedAsync and OnDisconnectedAsync methods. public override Task OnConnectedAsync() { ConnectedIds.Add( ...
Read more >
Use hubs in ASP.NET Core SignalR
The SignalR Hubs API enables connected clients to call methods on the server. ... does not need to be called in OnDisconnectedAsync, ...
Read more >
Use hub filters in ASP.NET Core SignalR
Create a filter by declaring a class that inherits from IHubFilter , and add the InvokeMethodAsync method. There is also OnConnectedAsync and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found