Skip to content

Commit a5b88af

Browse files
committed
deduplicate group messages across connections
1 parent d12915f commit a5b88af

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/SignalR/server/Core/src/DefaultHubLifetimeManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ public override Task SendGroupAsync(string groupName, string methodName, object?
225225
public override Task SendGroupsAsync(IReadOnlyList<string> groupNames, string methodName, object?[] args, CancellationToken cancellationToken = default)
226226
{
227227
// Each task represents the list of tasks for each of the writes within a group
228-
List<Task>? tasks = null;
229-
SerializedHubMessage? message = null;
228+
var connections = new ConcurrentDictionary<string, HubConnectionContext>();
230229

231230
foreach (var groupName in groupNames)
232231
{
@@ -238,13 +237,16 @@ public override Task SendGroupsAsync(IReadOnlyList<string> groupNames, string me
238237
var group = _groups[groupName];
239238
if (group != null)
240239
{
241-
DefaultHubLifetimeManager<THub>.SendToGroupConnections(methodName, args, group, null, null, ref tasks, ref message, cancellationToken);
240+
foreach (var connection in group)
241+
{
242+
connections.TryAdd(connection.Key, connection.Value);
243+
}
242244
}
243245
}
244246

245-
if (tasks != null)
247+
foreach (var connection in connections)
246248
{
247-
return Task.WhenAll(tasks);
249+
SendConnectionAsync(connection.Key, methodName, args, cancellationToken);
248250
}
249251

250252
return Task.CompletedTask;

0 commit comments

Comments
 (0)