Skip to content

[SignalR] receiving messages intended for another client #48690

@joriszwart

Description

@joriszwart

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have written a two-player game in which the game state is sent to other players.

I implemented this in .NET Core 2.2 and it worked. When I ported this to .NET 7.0 things got messed up in my game. It seems that messages intended for a specific client end up with other clients.

Expected Behavior

I do not expect to receive messages intended for other clients.

Steps To Reproduce

I wrote a minimal reproduction using a server (web app) and two clients (console app). It can be found here: github.com/joriszwart/signalr-unintended-client.

To reproduce, open three terminals in which you start a server and two clients respectively. This can be done without much haste, it does not seem to be a time-critical problem and can be reproduced consistently.

Server

dotnet run --project server
12:40:57.809 Server started.
12:41:00.512 New hub instance.
12:41:00.512 Client 8la6O8tOIlJXaTpKGMHvQg connected (connection count: 1)
12:41:00.517 Sent message '8la6O8tOIlJXaTpKGMHvQg' to 8la6O8tOIlJXaTpKGMHvQg.
12:41:02.481 New hub instance.
12:41:02.481 Client 6JK5AY26vk5LIQu4jbgd2A connected (connection count: 2)
12:41:02.481 Sent message '8la6O8tOIlJXaTpKGMHvQg' to 8la6O8tOIlJXaTpKGMHvQg.
12:41:02.481 Sent message '6JK5AY26vk5LIQu4jbgd2A' to 6JK5AY26vk5LIQu4jbgd2A.

Client 1

dotnet run --project client
12:41:00.511 Client 8la6O8tOIlJXaTpKGMHvQg started.
12:41:00.533 Client 8la6O8tOIlJXaTpKGMHvQg received message intended for client 8la6O8tOIlJXaTpKGMHvQg.

Client 2

dotnet run --project client
12:41:02.501 Client 6JK5AY26vk5LIQu4jbgd2A started.
12:41:02.501 Client 6JK5AY26vk5LIQu4jbgd2A received message intended for client 8la6O8tOIlJXaTpKGMHvQg.
12:41:02.506 Client 6JK5AY26vk5LIQu4jbgd2A received message intended for client 6JK5AY26vk5LIQu4jbgd2A.

What I observe here:

  1. Client 8la6O8tOIlJXaTpKGMHvQg correctly receives a message.
  2. Client 6JK5AY26vk5LIQu4jbgd2A incorrectly receives the message intended for 8la6O8tOIlJXaTpKGMHvQg.
  3. Client 6JK5AY26vk5LIQu4jbgd2A correctly receives a message.

Exceptions (if any)

No response

.NET Version

7.0.302

Anything else?

I discovered this in the NPM Package SignalR 7.0.5 but for the sake of reproducibility this reproduction uses a console app.

I'm aware that SignaLR groups are the better way to go (and I probably will), but I still wanted to address this.

Information about my environment follows, but I was able to reproduce this under Windows 11 as well.

ASP.Net Core Version: 7
IDE: Command line. (dotnet command)

.NET SDK:
 Version:   7.0.302
 Commit:    990cf98a27

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.4
 OS Platform: Darwin
 RID:         osx.13-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.302/

Host:
  Version:      7.0.5
  Architecture: arm64
  Commit:       8042d61b17

.NET SDKs installed:
  7.0.302 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/Users/joris/.dotnet]

global.json file:
  Not found

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions