From b90dfd2513ffd8d96a36d1ce084325b42402a1fb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 9 Apr 2021 09:00:00 -0700 Subject: [PATCH 1/2] Avoid closure caused by local function - Made the local function static and passed state via parameters. --- .../Core/src/Internal/DefaultHubDispatcher.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs index d3d4b92dfd33..867c11f7f6db 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs @@ -334,19 +334,30 @@ await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, else { // Invoke or Send - async Task ExecuteInvocation() + static async Task ExecuteInvocation(DefaultHubDispatcher dispatcher, + ObjectMethodExecutor methodExecutor, + THub hub, + object?[] arguments, + IServiceScope scope, + IHubActivator hubActivator, + HubConnectionContext connection, + HubMethodInvocationMessage hubMethodInvocationMessage, + bool isStreamCall) { + var logger = dispatcher._logger; + var enableDetailedErrors = dispatcher._enableDetailedErrors; + object? result; try { - result = await ExecuteHubMethod(methodExecutor, hub, arguments, connection, scope.ServiceProvider); - Log.SendingResult(_logger, hubMethodInvocationMessage.InvocationId, methodExecutor); + result = await dispatcher.ExecuteHubMethod(methodExecutor, hub, arguments, connection, scope.ServiceProvider); + Log.SendingResult(logger, hubMethodInvocationMessage.InvocationId, methodExecutor); } catch (Exception ex) { - Log.FailedInvokingHubMethod(_logger, hubMethodInvocationMessage.Target, ex); - await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, - ErrorMessageHelper.BuildErrorMessage($"An unexpected error occurred invoking '{hubMethodInvocationMessage.Target}' on the server.", ex, _enableDetailedErrors)); + Log.FailedInvokingHubMethod(logger, hubMethodInvocationMessage.Target, ex); + await dispatcher.SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, + ErrorMessageHelper.BuildErrorMessage($"An unexpected error occurred invoking '{hubMethodInvocationMessage.Target}' on the server.", ex, enableDetailedErrors)); return; } finally @@ -355,7 +366,7 @@ await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, // And normal invocations handle cleanup below in the finally if (isStreamCall) { - await CleanupInvocation(connection, hubMethodInvocationMessage, hubActivator, hub, scope); + await dispatcher.CleanupInvocation(connection, hubMethodInvocationMessage, hubActivator, hub, scope); } } @@ -366,7 +377,8 @@ await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, await connection.WriteAsync(CompletionMessage.WithResult(hubMethodInvocationMessage.InvocationId, result)); } } - invocation = ExecuteInvocation(); + + invocation = ExecuteInvocation(this, methodExecutor, hub, arguments, scope, hubActivator, connection, hubMethodInvocationMessage, isStreamCall); ; } if (isStreamCall || isStreamResponse) From f25e4407b04a97f5a7d527820ec8d992a07bfb66 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 9 Apr 2021 09:05:45 -0700 Subject: [PATCH 2/2] Too many semicolons --- src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs index 867c11f7f6db..07c235d63af0 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs @@ -378,7 +378,7 @@ await dispatcher.SendInvocationError(hubMethodInvocationMessage.InvocationId, co } } - invocation = ExecuteInvocation(this, methodExecutor, hub, arguments, scope, hubActivator, connection, hubMethodInvocationMessage, isStreamCall); ; + invocation = ExecuteInvocation(this, methodExecutor, hub, arguments, scope, hubActivator, connection, hubMethodInvocationMessage, isStreamCall); } if (isStreamCall || isStreamResponse)