Skip to content

Commit 985ef47

Browse files
[SignalR] Allocate HubCallerClients once per connection (#31661)
1 parent e5667a9 commit 985ef47

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/SignalR/server/Core/src/HubConnectionContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ internal StreamTracker StreamTracker
9999
}
100100

101101
internal HubCallerContext HubCallerContext { get; }
102+
internal HubCallerClients HubCallerClients { get; set; } = null!;
102103

103104
internal Exception? CloseException { get; private set; }
104105

src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public DefaultHubDispatcher(IServiceScopeFactory serviceScopeFactory, IHubContex
7474
public override async Task OnConnectedAsync(HubConnectionContext connection)
7575
{
7676
var scope = _serviceScopeFactory.CreateScope();
77+
connection.HubCallerClients = new HubCallerClients(_hubContext.Clients, connection.ConnectionId);
7778

7879
try
7980
{
@@ -558,7 +559,7 @@ private async Task SendInvocationError(string? invocationId,
558559

559560
private void InitializeHub(THub hub, HubConnectionContext connection)
560561
{
561-
hub.Clients = new HubCallerClients(_hubContext.Clients, connection.ConnectionId);
562+
hub.Clients = connection.HubCallerClients;
562563
hub.Context = connection.HubCallerContext;
563564
hub.Groups = _hubContext.Groups;
564565
}

0 commit comments

Comments
 (0)