From 221c95e0afa9b87d47842722ef8b4112b046495a Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Mon, 2 Apr 2018 19:25:47 -0700 Subject: [PATCH] Couple logging additions (#1827) - Added logging in a couple more places in HubConnection - Increase DEFAULT_TIMEOUT_INTERVAL to 20 seconds --- clients/ts/FunctionalTests/ts/Utils.ts | 4 ++++ clients/ts/signalr/spec/Utils.ts | 2 ++ clients/ts/signalr/src/Utils.ts | 2 ++ .../Internal/ServerSentEventsTransport.cs | 1 + .../HubConnection.cs | 4 +++- .../HubConnectionHandler.cs | 19 +++++++++++++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clients/ts/FunctionalTests/ts/Utils.ts b/clients/ts/FunctionalTests/ts/Utils.ts index 8aab74f903..2379cfdc57 100644 --- a/clients/ts/FunctionalTests/ts/Utils.ts +++ b/clients/ts/FunctionalTests/ts/Utils.ts @@ -1,3 +1,7 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; export function getParameterByName(name: string) { const url = window.location.href; diff --git a/clients/ts/signalr/spec/Utils.ts b/clients/ts/signalr/spec/Utils.ts index 4df320a066..46c397d12a 100644 --- a/clients/ts/signalr/spec/Utils.ts +++ b/clients/ts/signalr/spec/Utils.ts @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; + export function asyncit(expectation: string, assertion?: () => Promise | void, timeout?: number): void { let testFunction: (done: DoneFn) => void; if (assertion) { diff --git a/clients/ts/signalr/src/Utils.ts b/clients/ts/signalr/src/Utils.ts index 72d0ad875a..3bc5e2f1af 100644 --- a/clients/ts/signalr/src/Utils.ts +++ b/clients/ts/signalr/src/Utils.ts @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; + export class Arg { public static isRequired(val: any, name: string): void { if (val === null || val === undefined) { diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ServerSentEventsTransport.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ServerSentEventsTransport.cs index 8b930015fe..029f56f1c8 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ServerSentEventsTransport.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ServerSentEventsTransport.cs @@ -160,6 +160,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal // or if the consumer is done if (flushResult.IsCanceled || flushResult.IsCompleted) { + Log.EventStreamEnded(_logger); break; } } diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index 8d1c76b415..d7a221763f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -553,7 +553,9 @@ namespace Microsoft.AspNetCore.SignalR.Client } } } - catch (Exception ex) + // Ignore HubException because we throw it when we receive a handshake response with an error + // And we don't need to log that the handshake failed + catch (Exception ex) when (!(ex is HubException)) { // shutdown if we're unable to read handshake Log.ErrorReceivingHandshakeResponse(_logger, ex); diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs index 7927e13e06..03c7753943 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs @@ -57,6 +57,8 @@ namespace Microsoft.AspNetCore.SignalR throw new InvalidOperationException("There are no supported protocols"); } + Log.ConnectedStarting(_logger); + var connectionContext = new HubConnectionContext(connection, keepAlive, _loggerFactory); if (!await connectionContext.HandshakeAsync(handshakeTimeout, supportedProtocols, _protocolResolver, _userIdProvider, _enableDetailedErrors)) @@ -71,6 +73,7 @@ namespace Microsoft.AspNetCore.SignalR } finally { + Log.ConnectedEnding(_logger); await _lifetimeManager.OnDisconnectedAsync(connectionContext); } } @@ -215,6 +218,12 @@ namespace Microsoft.AspNetCore.SignalR private static readonly Action _errorSendingClose = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "ErrorSendingClose"), "Error when sending Close message."); + private static readonly Action _connectedStarting = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, "ConnectedStarting"), "OnConnectedAsync started."); + + private static readonly Action _connectedEnding = + LoggerMessage.Define(LogLevel.Debug, new EventId(6, "ConnectedEnding"), "OnConnectedAsync ending."); + public static void ErrorDispatchingHubEvent(ILogger logger, string hubMethod, Exception exception) { _errorDispatchingHubEvent(logger, hubMethod, exception); @@ -234,6 +243,16 @@ namespace Microsoft.AspNetCore.SignalR { _errorSendingClose(logger, exception); } + + public static void ConnectedStarting(ILogger logger) + { + _connectedStarting(logger, null); + } + + public static void ConnectedEnding(ILogger logger) + { + _connectedEnding(logger, null); + } } } }