diff --git a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs index 0ecf1f8290..5c135f381a 100644 --- a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs +++ b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs @@ -491,13 +491,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [LogLevel(LogLevel.Trace)] public async Task StreamAsyncDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } var protocol = HubProtocols[protocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); try @@ -901,16 +896,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [LogLevel(LogLevel.Trace)] public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path) { - bool ExpectedErrors(WriteContext writeContext) - { - // Writing is not allowed after writer was completed. - // Can happen since we are closing the connection while the connection could still be writing the streaming data - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "FailedWritingMessage"; - } - var protocol = HubProtocols[protocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); try @@ -1013,14 +1000,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1046,14 +1027,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1079,14 +1054,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsList))] public async Task ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch(string hubProtocolName) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, hubProtocol, LoggerFactory); try @@ -1112,14 +1081,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1145,14 +1108,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1179,14 +1136,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1213,14 +1164,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1247,14 +1192,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "NonStreamingMethodCalledWithStream"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1280,14 +1219,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "StreamingMethodCalledWithInvoke"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1313,14 +1246,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] public async Task ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible(string hubProtocolName, HttpTransportType transportType, string hubPath) { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == DefaultHubDispatcherLoggerName && - writeContext.EventId.Name == "InvalidReturnValueFromStreamingMethod"; - } - var hubProtocol = HubProtocols[hubProtocolName]; - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); try @@ -1345,16 +1272,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests [Fact] public async Task RandomGenericIsNotTreatedAsStream() { - bool ExpectedErrors(WriteContext writeContext) - { - return "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" == writeContext.LoggerName && - "FailedInvokingHubMethod" == writeContext.EventId.Name; - } var hubPath = HubPaths[0]; var hubProtocol = HubProtocols.First().Value; var transportType = TransportTypes().First().Cast().First(); - using (StartServer(out var server, ExpectedErrors)) + using (StartServer(out var server)) { var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); await connection.StartAsync().OrTimeout(); diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs index 5bcf32c39a..af91f08af2 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.Log.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal LoggerMessage.Define(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this connection handler."); private static readonly Action _cannotChangeTransport = - LoggerMessage.Define(LogLevel.Error, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}."); private static readonly Action _postNotallowedForWebsockets = LoggerMessage.Define(LogLevel.Debug, new EventId(9, "PostNotAllowedForWebSockets"), "POST requests are not allowed for websocket connections."); diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs similarity index 93% rename from src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs rename to src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs index 75a2438f62..b847ef9984 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.Log.cs @@ -45,10 +45,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports LoggerMessage.Define(LogLevel.Trace, new EventId(11, "SendPayload"), "Sending payload: {Size} bytes."); private static readonly Action _errorWritingFrame = - LoggerMessage.Define(LogLevel.Error, new EventId(12, "ErrorWritingFrame"), "Error writing frame."); + LoggerMessage.Define(LogLevel.Debug, new EventId(12, "ErrorWritingFrame"), "Error writing frame."); - private static readonly Action _sendFailed = - LoggerMessage.Define(LogLevel.Error, new EventId(13, "SendFailed"), "Socket failed to send."); + // 13, SendFailed - removed private static readonly Action _closedPrematurely = LoggerMessage.Define(LogLevel.Debug, new EventId(14, "ClosedPrematurely"), "Socket connection closed prematurely."); @@ -116,11 +115,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports _errorWritingFrame(logger, ex); } - public static void SendFailed(ILogger logger, Exception ex) - { - _sendFailed(logger, ex); - } - public static void ClosedPrematurely(ILogger logger, Exception ex) { _closedPrematurely(logger, ex); diff --git a/src/SignalR/server/Core/src/HubConnectionContext.cs b/src/SignalR/server/Core/src/HubConnectionContext.cs index 22400fa702..ba3a8a0201 100644 --- a/src/SignalR/server/Core/src/HubConnectionContext.cs +++ b/src/SignalR/server/Core/src/HubConnectionContext.cs @@ -593,7 +593,7 @@ namespace Microsoft.AspNetCore.SignalR { // Category: HubConnectionContext private static readonly Action _handshakeComplete = - LoggerMessage.Define(LogLevel.Information, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'."); private static readonly Action _handshakeCanceled = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "HandshakeCanceled"), "Handshake was canceled."); @@ -605,13 +605,13 @@ namespace Microsoft.AspNetCore.SignalR LoggerMessage.Define(LogLevel.Debug, new EventId(4, "TransportBufferFull"), "Unable to send Ping message to client, the transport buffer is full."); private static readonly Action _handshakeFailed = - LoggerMessage.Define(LogLevel.Error, new EventId(5, "HandshakeFailed"), "Failed connection handshake."); + LoggerMessage.Define(LogLevel.Debug, new EventId(5, "HandshakeFailed"), "Failed connection handshake."); private static readonly Action _failedWritingMessage = - LoggerMessage.Define(LogLevel.Error, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection."); private static readonly Action _protocolVersionFailed = - LoggerMessage.Define(LogLevel.Warning, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol."); private static readonly Action _abortFailed = LoggerMessage.Define(LogLevel.Trace, new EventId(8, "AbortFailed"), "Abort callback failed."); diff --git a/src/SignalR/server/Core/src/HubConnectionHandler.cs b/src/SignalR/server/Core/src/HubConnectionHandler.cs index 252f7436da..de6a3dd3c0 100644 --- a/src/SignalR/server/Core/src/HubConnectionHandler.cs +++ b/src/SignalR/server/Core/src/HubConnectionHandler.cs @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.SignalR LoggerMessage.Define(LogLevel.Error, new EventId(1, "ErrorDispatchingHubEvent"), "Error when dispatching '{HubMethod}' on hub."); private static readonly Action _errorProcessingRequest = - LoggerMessage.Define(LogLevel.Error, new EventId(2, "ErrorProcessingRequest"), "Error when processing requests."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, "ErrorProcessingRequest"), "Error when processing requests."); private static readonly Action _abortFailed = LoggerMessage.Define(LogLevel.Trace, new EventId(3, "AbortFailed"), "Abort callback failed."); diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs index 0d241a19ae..fb7e09cb4a 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.Log.cs @@ -16,13 +16,12 @@ namespace Microsoft.AspNetCore.SignalR.Internal LoggerMessage.Define(LogLevel.Debug, new EventId(1, "ReceivedHubInvocation"), "Received hub invocation: {InvocationMessage}."); private static readonly Action _unsupportedMessageReceived = - LoggerMessage.Define(LogLevel.Error, new EventId(2, "UnsupportedMessageReceived"), "Received unsupported message of type '{MessageType}'."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, "UnsupportedMessageReceived"), "Received unsupported message of type '{MessageType}'."); private static readonly Action _unknownHubMethod = - LoggerMessage.Define(LogLevel.Error, new EventId(3, "UnknownHubMethod"), "Unknown hub method '{HubMethod}'."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, "UnknownHubMethod"), "Unknown hub method '{HubMethod}'."); - private static readonly Action _outboundChannelClosed = - LoggerMessage.Define(LogLevel.Warning, new EventId(4, "OutboundChannelClosed"), "Outbound channel was closed while trying to write hub message."); + // 4, OutboundChannelClosed - removed private static readonly Action _hubMethodNotAuthorized = LoggerMessage.Define(LogLevel.Debug, new EventId(5, "HubMethodNotAuthorized"), "Failed to invoke '{HubMethod}' because user is unauthorized."); @@ -49,13 +48,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal LoggerMessage.Define(LogLevel.Debug, new EventId(12, "ReceivedStreamHubInvocation"), "Received stream hub invocation: {InvocationMessage}."); private static readonly Action _streamingMethodCalledWithInvoke = - LoggerMessage.Define(LogLevel.Error, new EventId(13, "StreamingMethodCalledWithInvoke"), "A streaming method was invoked with a non-streaming invocation : {InvocationMessage}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(13, "StreamingMethodCalledWithInvoke"), "A streaming method was invoked with a non-streaming invocation : {InvocationMessage}."); private static readonly Action _nonStreamingMethodCalledWithStream = - LoggerMessage.Define(LogLevel.Error, new EventId(14, "NonStreamingMethodCalledWithStream"), "A non-streaming method was invoked with a streaming invocation : {InvocationMessage}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(14, "NonStreamingMethodCalledWithStream"), "A non-streaming method was invoked with a streaming invocation : {InvocationMessage}."); private static readonly Action _invalidReturnValueFromStreamingMethod = - LoggerMessage.Define(LogLevel.Error, new EventId(15, "InvalidReturnValueFromStreamingMethod"), "A streaming method returned a value that cannot be used to build enumerator {HubMethod}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(15, "InvalidReturnValueFromStreamingMethod"), "A streaming method returned a value that cannot be used to build enumerator {HubMethod}."); private static readonly Action _receivedStreamItem = LoggerMessage.Define(LogLevel.Trace, new EventId(16, "ReceivedStreamItem"), "Received item for stream '{StreamId}'."); @@ -67,7 +66,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal LoggerMessage.Define(LogLevel.Trace, new EventId(18, "CompletingStream"), "Stream '{StreamId}' has been completed by client."); private static readonly Action _closingStreamWithBindingError = - LoggerMessage.Define(LogLevel.Warning, new EventId(19, "ClosingStreamWithBindingError"), "Stream '{StreamId}' closed with error '{Error}'."); + LoggerMessage.Define(LogLevel.Debug, new EventId(19, "ClosingStreamWithBindingError"), "Stream '{StreamId}' closed with error '{Error}'."); private static readonly Action _unexpectedStreamCompletion = LoggerMessage.Define(LogLevel.Debug, new EventId(20, "UnexpectedStreamCompletion"), "StreamCompletionMessage received unexpectedly."); @@ -75,6 +74,9 @@ namespace Microsoft.AspNetCore.SignalR.Internal private static readonly Action _unexpectedStreamItem = LoggerMessage.Define(LogLevel.Debug, new EventId(21, "UnexpectedStreamItem"), "StreamItemMessage received unexpectedly."); + private static readonly Action _invalidHubParameters = + LoggerMessage.Define(LogLevel.Debug, new EventId(22, "InvalidHubParameters"), "Parameters to hub method '{HubMethod}' are incorrect."); + public static void ReceivedHubInvocation(ILogger logger, InvocationMessage invocationMessage) { _receivedHubInvocation(logger, invocationMessage, null); @@ -90,11 +92,6 @@ namespace Microsoft.AspNetCore.SignalR.Internal _unknownHubMethod(logger, hubMethod, null); } - public static void OutboundChannelClosed(ILogger logger) - { - _outboundChannelClosed(logger, null); - } - public static void HubMethodNotAuthorized(ILogger logger, string hubMethod) { _hubMethodNotAuthorized(logger, hubMethod, null); @@ -184,6 +181,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal { _unexpectedStreamItem(logger, null); } + + public static void InvalidHubParameters(ILogger logger, string hubMethod, Exception exception) + { + _invalidHubParameters(logger, hubMethod, exception); + } } } } diff --git a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs index f1975e12bc..cead347976 100644 --- a/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs +++ b/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs @@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal private Task ProcessInvocationBindingFailure(HubConnectionContext connection, InvocationBindingFailureMessage bindingFailureMessage) { - Log.FailedInvokingHubMethod(_logger, bindingFailureMessage.Target, bindingFailureMessage.BindingFailure.SourceException); + Log.InvalidHubParameters(_logger, bindingFailureMessage.Target, bindingFailureMessage.BindingFailure.SourceException); var errorMessage = ErrorMessageHelper.BuildErrorMessage($"Failed to invoke '{bindingFailureMessage.Target}' due to an error on the server.", bindingFailureMessage.BindingFailure.SourceException, _enableDetailedErrors); @@ -243,7 +243,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal var serverStreamLength = descriptor.StreamingParameters?.Count ?? 0; if (clientStreamLength != serverStreamLength) { - throw new HubException($"Client sent {clientStreamLength} stream(s), Hub method expects {serverStreamLength}."); + var ex = new HubException($"Client sent {clientStreamLength} stream(s), Hub method expects {serverStreamLength}."); + Log.InvalidHubParameters(_logger, hubMethodInvocationMessage.Target, ex); + await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection, + ErrorMessageHelper.BuildErrorMessage($"An unexpected error occurred invoking '{hubMethodInvocationMessage.Target}' on the server.", ex, _enableDetailedErrors)); + return; } InitializeHub(hub, connection); diff --git a/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs b/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs index c61a1b1c00..d4188e3918 100644 --- a/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs +++ b/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs @@ -163,13 +163,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task MissingHandshakeAndMessageSentFromHubConnectionCanBeDisposedCleanly() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "HandshakeFailed"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); var connectionHandler = serviceProvider.GetService>(); @@ -251,13 +245,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task HandshakeFailureFromUnknownProtocolSendsResponseWithError() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "HandshakeFailed"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var hubProtocolMock = new Mock(); hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol"); @@ -281,13 +269,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task HandshakeFailureFromUnsupportedFormatSendsResponseWithError() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "HandshakeFailed"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var hubProtocolMock = new Mock(); hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol"); @@ -460,19 +442,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e"); var maximumMessageSize = payload.Length - 10; - InvalidDataException exception = null; - bool ExpectedErrors(WriteContext writeContext) - { - if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide)) - { - exception = ide; - return true; - } - return false; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory, services => services.AddSignalR().AddHubOptions(o => o.MaximumReceiveMessageSize = maximumMessageSize)); @@ -489,8 +460,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - Assert.NotNull(exception); - Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); + var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") && + (w.Exception is InvalidDataException ide)); + Assert.Single(exceptionLog); + Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); } [Fact] @@ -498,19 +471,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e"); var maximumMessageSize = payload.Length - 10; - InvalidDataException exception = null; - bool ExpectedErrors(WriteContext writeContext) - { - if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide)) - { - exception = ide; - return true; - } - return false; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory, services => services.AddSignalR().AddHubOptions(o => o.MaximumReceiveMessageSize = maximumMessageSize)); @@ -528,8 +490,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - Assert.NotNull(exception); - Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); + var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") && + (w.Exception is InvalidDataException ide)); + Assert.Single(exceptionLog); + Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); } [Fact] @@ -542,19 +506,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // Between the first and the second payload so we'll end up slicing with some remaining in the slice for // the next message var maximumMessageSize = payload1.Length + 1; - InvalidDataException exception = null; - - bool ExpectedErrors(WriteContext writeContext) - { - if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide)) - { - exception = ide; - return true; - } - return false; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory, services => services.AddSignalR().AddHubOptions(o => o.MaximumReceiveMessageSize = maximumMessageSize)); @@ -589,8 +541,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - Assert.NotNull(exception); - Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); + var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") && + (w.Exception is InvalidDataException ide)); + Assert.Single(exceptionLog); + Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions."); } [Fact] @@ -668,13 +622,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task ConnectionClosesOnServerWithPartialHandshakeMessageAndCompletedPipe() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "HandshakeFailed"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), loggerFactory: LoggerFactory); @@ -1170,13 +1118,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CannotCallOverriddenBaseHubMethod() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); @@ -1220,13 +1162,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CannotCallStaticHubMethods() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); @@ -1251,13 +1187,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CannotCallObjectMethodsOnHub() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); @@ -1290,13 +1220,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CannotCallDisposeMethodOnHub() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); @@ -2995,13 +2919,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task ServerSendsCloseWithErrorWhenConnectionClosedWithPartialMessage() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && - writeContext.EventId.Name == "ErrorProcessingRequest"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { @@ -3154,14 +3072,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact(Skip = "Cyclic parsing is not supported yet")] public async Task ConnectionAbortedIfSendFailsWithProtocolError() { - bool ExpectedErrors(WriteContext writeContext) - { - // Self referencing class will cause write failure - return writeContext.LoggerName == typeof(HubConnectionContext).FullName && - writeContext.EventId.Name == "FailedWritingMessage"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { @@ -3333,13 +3244,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task UploadStreamWithTooManyStreamsFails() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(loggerFactory: LoggerFactory); var connectionHandler = serviceProvider.GetService>(); @@ -3358,13 +3263,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task UploadStreamWithTooFewStreamsFails() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(loggerFactory: LoggerFactory); var connectionHandler = serviceProvider.GetService>(); @@ -3570,13 +3469,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task InvokeHubMethodCannotAcceptCancellationTokenAsArgument() { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && - writeContext.EventId.Name == "FailedInvokingHubMethod"; - } - - using (StartVerifiableLog(ExpectedErrors)) + using (StartVerifiableLog()) { var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory); var connectionHandler = serviceProvider.GetService>(); diff --git a/src/SignalR/server/StackExchangeRedis/src/Internal/RedisLog.cs b/src/SignalR/server/StackExchangeRedis/src/Internal/RedisLog.cs index bd8d228ee3..51b939e84d 100644 --- a/src/SignalR/server/StackExchangeRedis/src/Internal/RedisLog.cs +++ b/src/SignalR/server/StackExchangeRedis/src/Internal/RedisLog.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Internal LoggerMessage.Define(LogLevel.Error, new EventId(9, "ConnectionFailed"), "Connection to Redis failed."); private static readonly Action _failedWritingMessage = - LoggerMessage.Define(LogLevel.Warning, new EventId(10, "FailedWritingMessage"), "Failed writing message."); + LoggerMessage.Define(LogLevel.Debug, new EventId(10, "FailedWritingMessage"), "Failed writing message."); private static readonly Action _internalMessageFailed = LoggerMessage.Define(LogLevel.Warning, new EventId(11, "InternalMessageFailed"), "Error processing message for internal server message.");