Skip to content
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

A server node cannot send messages to clients before Azure SignalR assigns the first client connection to it #1937

Closed
engmarknabil opened this issue May 14, 2024 · 4 comments

Comments

@engmarknabil
Copy link

Description

When having multiple server nodes, each node cannot send messages to clients until Azure SignalR assigns the first client connection to it. Before that, Hub.Clients is null.

To Reproduce

Clone this repo and follow the readme

Exceptions (if any)

Further technical details

  • Azure SignalR SDK version: 1.25.2
  • Server ASPNETCORE version: 8.0
  • SignalR Client SDK version: 8.0.4
@nfogg
Copy link

nfogg commented May 16, 2024

Hello,
I am a colleague of @engmarknabil and can give some additional details.

We have implemented a Hub subclass named ClientEventService and during the backend server application launch we see messages like:

[12:12:23] info: Microsoft.Azure.SignalR.ServiceConnection[20] Service connection c2b8c44a-92dd-4ef9-8d08-4286f0fb0000 connected.
[12:12:23] info: Microsoft.Azure.SignalR.StrongServiceConnectionContainer[1] Hub 'ClientEventService' is now connected to '(Primary)https://*****-signalr.service.signalr.net(hub=ClientEventService)'.

The backend servers are in a cluster. SignalR is used by the backend to forward events to frontend clients.

We have noticed some unexpected behaviour.

After backend application launch we are able to accept new client connections and everything works as expected once at least one client connects to each backend instance.

Once the first inbound client connection is made the instance can then send messages to any connected client, even if that client never connected to this instance.

However, a backend server is unable to send messages to any clients until it has received at least one incoming client connection. Until a client connection is received, the Clients property of the Hub is empty.

This is a problem for us as under light load following a deployment, a backend instance may need to react to external events and send messages to one or more connected clients before having received any client connection requests. We have chosen Azure SignalR in order to abstract the management of client connections and allow any backend instance to communicate with any client.

Is our observed behaviour expected? If so, are there any recommended mitigations?

@vwxyzh
Copy link
Contributor

vwxyzh commented May 21, 2024

@engmarknabil
please following this document.

in simple words:

  1. require IHubContext<YourHub> from DI
  2. send message by the hub context, e.g.: context.Clients.SendAsync("test-client")

@terencefan
Copy link
Member

sample PR: engmarknabil/SignalRTester#1

@engmarknabil
Copy link
Author

Thanks @vwxyzh and @terencefan. That solved our issue.

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

No branches or pull requests

4 participants