Skip to content

Commit 79280df

Browse files
committed
fix
1 parent 63edb9b commit 79280df

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

src/SignalR/server/Core/src/HubOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class HubOptions
5656

5757
/// <summary>
5858
/// By default a client is only allowed to invoke a single Hub method at a time.
59-
/// Changing this property will allow clients to invoke multiple invocations at the same time before queueing.
59+
/// Changing this property will allow clients to invoke multiple methods at the same time before queueing.
6060
/// </summary>
6161
public int MaxParallelInvocationsPerClient
6262
{

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,19 @@ async Task ExecuteStreamInvocation()
331331
{
332332
cts = cts ?? CancellationTokenSource.CreateLinkedTokenSource(connection.ConnectionAborted);
333333
connection.ActiveRequestCancellationSources.TryAdd(hubMethodInvocationMessage.InvocationId, cts);
334+
object result;
334335

335-
var result = await ExecuteHubMethod(methodExecutor, hub, arguments, connection, scope.ServiceProvider);
336+
try
337+
{
338+
result = await ExecuteHubMethod(methodExecutor, hub, arguments, connection, scope.ServiceProvider);
339+
}
340+
catch (Exception ex)
341+
{
342+
Log.FailedInvokingHubMethod(_logger, hubMethodInvocationMessage.Target, ex);
343+
await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection,
344+
ErrorMessageHelper.BuildErrorMessage($"An unexpected error occurred invoking '{hubMethodInvocationMessage.Target}' on the server.", ex, _enableDetailedErrors));
345+
return;
346+
}
336347

337348
if (result == null)
338349
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
14
using System;
25
using System.Threading;
36
using System.Threading.Tasks;

src/SignalR/server/SignalR/test/AddSignalRTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Connections;
10+
using Microsoft.AspNetCore.SignalR;
1011
using Microsoft.AspNetCore.SignalR.Internal;
1112
using Microsoft.AspNetCore.SignalR.Protocol;
1213
using Microsoft.Extensions.DependencyInjection;
@@ -78,11 +79,15 @@ public void HubSpecificOptionsDoNotAffectGlobalHubOptions()
7879
serviceCollection.AddSignalR().AddHubOptions<CustomHub>(options =>
7980
{
8081
options.SupportedProtocols.Clear();
82+
options.AddFilter(new CustomHubFilter());
8183
});
8284

8385
var serviceProvider = serviceCollection.BuildServiceProvider();
8486
Assert.Equal(1, serviceProvider.GetRequiredService<IOptions<HubOptions>>().Value.SupportedProtocols.Count);
8587
Assert.Equal(0, serviceProvider.GetRequiredService<IOptions<HubOptions<CustomHub>>>().Value.SupportedProtocols.Count);
88+
89+
Assert.Null(serviceProvider.GetRequiredService<IOptions<HubOptions>>().Value.HubFilters);
90+
Assert.Single(serviceProvider.GetRequiredService<IOptions<HubOptions<CustomHub>>>().Value.HubFilters);
8691
}
8792

8893
[Fact]
@@ -342,6 +347,14 @@ public void WriteMessage(HubMessage message, IBufferWriter<byte> output)
342347
throw new NotImplementedException();
343348
}
344349
}
350+
351+
internal class CustomHubFilter : IHubFilter
352+
{
353+
public ValueTask<object> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object>> next)
354+
{
355+
throw new NotImplementedException();
356+
}
357+
}
345358
}
346359

347360
namespace Microsoft.AspNetCore.SignalR.Internal

src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,7 +2794,6 @@ public async Task ConnectionTimesOutIfInitialPingAndThenNoMessages()
27942794
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
27952795
await client.Connected.OrTimeout();
27962796
await client.SendHubMessageAsync(PingMessage.Instance);
2797-
await client.InvokeAsync(nameof(MethodHub.ValueMethod));
27982797

27992798
clock.UtcNow = clock.UtcNow.AddMilliseconds(timeout + 1);
28002799
client.TickHeartbeat();
@@ -2945,7 +2944,7 @@ public async Task HubMethodInvokeDoesNotCountTowardsClientTimeout()
29452944

29462945
// Invoke another hub method (which will be blocked by the first method) in order to stop the timeout
29472946
// This is how a real-world example would behave
2948-
await client.SendInvocationAsync(nameof(LongRunningHub.LongRunningMethod));
2947+
await client.SendInvocationAsync(nameof(LongRunningHub.LongRunningMethod)).OrTimeout();
29492948

29502949
// Tick heartbeat while hub method is running to show that close isn't triggered
29512950
client.TickHeartbeat();

0 commit comments

Comments
 (0)