Skip to content

OnConnectedAsync ist sometimes called with the wrong HubConnectionContext #53731

@Machibuse

Description

@Machibuse

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a c# SignalR Server and Client.

The connections are authenticated via a AuthenticationHandler that checks a http header and sets NameIdentifier claim on success.

I have overridden OnConnectedAsync like this:

public override Task OnConnectedAsync()
{
    Logger.LogDebug("OnConnectedAsync {UserIdentifier} {ConnectionId}", Context.UserIdentifier, Context.ConnectionId);
    return Task.CompletedTask;
}

Now i have 12 Clients connecting sequencially to the Host, everything works fine, i see 12 different Users and ConnectionIds in the log.

When i now restart the host, all 12 clients get disconnected an they reconnects after a few seconds. All nearly exact at the same time.

Now i can see 12 log entries in my log, but not all entries have different connection Ids. Some times there are 12 log entrys with the same ConnectionId and the Same UserIdentifier, sometimes 2 or 3 Different ConnectionIds.

But there are always Exact 12 Log entrys and all clients are connected.

Log looks like this

OnConnectedAsync bx-1112-a15b Auh6pXikG_Z_yv-DKd2f7w
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A
OnConnectedAsync bx-6d0d-a085 lAHrxx264qEiy3DVGyBr3A

Expected Behavior

The resulting log should look more like this

OnConnectedAsync bx-559c-bf6b -AuuForEsEmkekc7zl-MFg
OnConnectedAsync bx-8136-3d61 vGzZ3ueAEfXoywbvPRCe8w
OnConnectedAsync bx-a879-10bf q3R7KdUJNBIJX9NsCEZjUg
OnConnectedAsync bx-1112-a15b APXIiXndlvToA7EGRGp6Sg
OnConnectedAsync bx-6d0d-a085 vnigiIvux6uZTFUdJ8jaZQ
OnConnectedAsync bx-5074-7cdf UxnUyiiDnNExL9Zsi2BZGQ
OnConnectedAsync bx-ab74-7078 v_w2XHaL2hWFsdEz0biTFQ
OnConnectedAsync bx-f865-0aa5 hwKVxqG_PcHlhnBxTF7mnQ
OnConnectedAsync bx-078b-ba40 iZ4v7sCklCsSa1fYGBHTBA
OnConnectedAsync bx-4bb1-2f20 ymKoUF7OU0lwu1_otgkvkg
OnConnectedAsync bx-e8fa-cae0 GOVZoyQrHQH22qb5BiQi7g
OnConnectedAsync bx-8136-3d61 NRqC5IIPIBAL2Dz4fJH_kA

this.Context shoult point to the correct HubConnectionContext inside OnConnectedAsync

Steps To Reproduce

If you need ist, i can try to make a small sample Project that reproduces the problem. If you have questione or any ideas what i can try, feel free to ask me.

Exceptions (if any)

I have tested the behavior on different Computers and it seems that there are no problems when the Host ist running on a very slow machine

.NET Version

Microsoft.AspNetCore.App 8.0.1

Anything else?

No response

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