Skip to content

Commit

Permalink
Merge pull request #413 from vicancy/r107
Browse files Browse the repository at this point in the history
Releasing 1.0.7 with some hotfix
  • Loading branch information
vicancy authored Feb 26, 2019
2 parents 57dc13b + 9c98211 commit fca8acb
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 13 deletions.
8 changes: 4 additions & 4 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<PropertyGroup Label="Package Versions">
<!-- Azure ASP.NET Core SignalR -->
<MessagePackPackageVersion>1.7.3.4</MessagePackPackageVersion>
<MicrosoftAspNetCoreHttpConnectionsClientPackageVersion>1.1.0</MicrosoftAspNetCoreHttpConnectionsClientPackageVersion>
<MicrosoftAspNetCoreSignalRPackageVersion>1.1.0</MicrosoftAspNetCoreSignalRPackageVersion>
<MicrosoftAspNetCoreHttpConnectionsClientPackageVersion>1.0.0</MicrosoftAspNetCoreHttpConnectionsClientPackageVersion>
<MicrosoftAspNetCoreSignalRPackageVersion>1.0.0</MicrosoftAspNetCoreSignalRPackageVersion>
<MicrosoftIdentitiyModelClientsActiveDirectoryPackageVersion>3.19.1</MicrosoftIdentitiyModelClientsActiveDirectoryPackageVersion>
<MicrosoftAzureKeyVaultPackageVersion>2.3.2</MicrosoftAzureKeyVaultPackageVersion>
<SystemBuffersPackageVersion>4.5.0</SystemBuffersPackageVersion>
Expand All @@ -19,7 +19,7 @@

<!-- Azure ASP.NET SignalR -->
<MicrosoftAspNetSignalRPackageVersion>2.4.0</MicrosoftAspNetSignalRPackageVersion>
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.2.0</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.1.0</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
<MicrosoftExtensionsLoggingTraceSourcePackageVersion>2.1.0</MicrosoftExtensionsLoggingTraceSourcePackageVersion>
<SystemThreadingChannelsPackageVersion>4.5.0</SystemThreadingChannelsPackageVersion>

Expand All @@ -40,7 +40,7 @@
<OwinPackageVersion>1.0.0</OwinPackageVersion>

<!--Testing -->
<MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>1.1.0</MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>
<MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>1.0.0</MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
<MoqPackageVersion>4.7.49</MoqPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
Expand Down
32 changes: 31 additions & 1 deletion src/Microsoft.Azure.SignalR.AspNet/TraceManagerLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using Microsoft.AspNet.SignalR.Tracing;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.TraceSource;
Expand All @@ -19,11 +21,39 @@ public TraceManagerLoggerProvider(ITraceManager traceManager)
public ILogger CreateLogger(string categoryName)
{
var traceSource = _traceManager[categoryName];
return new TraceSourceLogger(traceSource);
return new InternalTraceSourceLogger(traceSource);
}

public void Dispose()
{
}

/// <summary>
/// Use an InternalTraceSourceLogger to get rid of LogicalOperationStack inside the TraceSourceScope
/// </summary>
private class InternalTraceSourceLogger : ILogger
{
private readonly ILogger _inner;

public InternalTraceSourceLogger(TraceSource traceSource)
{
_inner = new TraceSourceLogger(traceSource);
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
_inner.Log(logLevel, eventId, state, exception, formatter);
}

public bool IsEnabled(LogLevel logLevel)
{
return _inner.IsEnabled(logLevel);
}

public IDisposable BeginScope<TState>(TState state)
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,16 @@ private async Task<bool> ReceiveHandshakeResponseAsync(PipeReader input, Cancell
}

// Handshake error. Will stop reconnect.
Log.HandshakeError(_logger, handshakeResponse.ErrorMessage);
if (_connectionType == ServerConnectionType.OnDemand)
{
// Handshake errors on on-demand connections are acceptable.
Log.OnDemandConnectionHandshakeResponse(_logger, handshakeResponse.ErrorMessage);
}
else
{
Log.HandshakeError(_logger, handshakeResponse.ErrorMessage);
}

return false;
}
}
Expand Down Expand Up @@ -603,6 +612,9 @@ private static class Log
private static readonly Action<ILogger, string, Exception> _unexpectedExceptionInStop =
LoggerMessage.Define<string>(LogLevel.Warning, new EventId(29, "UnexpectedExceptionInStop"), "Connection {ServiceConnectionId} got unexpected exception in StopAsync.");

private static readonly Action<ILogger, string, Exception> _onDemandConnectionHandshakeResponse =
LoggerMessage.Define<string>(LogLevel.Information, new EventId(30, "OnDemandConnectionHandshakeResponse"), "Service returned handshake response: {Message}");

public static void FailedToWrite(ILogger logger, Exception exception)
{
_failedToWrite(logger, exception);
Expand Down Expand Up @@ -730,6 +742,11 @@ public static void HandshakeError(ILogger logger, string error)
_handshakeError(logger, error, null);
}

public static void OnDemandConnectionHandshakeResponse(ILogger logger, string message)
{
_onDemandConnectionHandshakeResponse(logger, message, null);
}

public static void SentPing(ILogger logger)
{
_sentPing(logger, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ public TestServiceConnectionManager(string appName, IReadOnlyList<string> hubs)

public override Task WriteAsync(ServiceMessage serviceMessage)
{
var tcs = _waitForTransportOutputMessage.GetOrAdd(serviceMessage.GetType(), i => new TaskCompletionSource<ServiceMessage>());
tcs.TrySetResult(serviceMessage);
if (_waitForTransportOutputMessage.TryGetValue(serviceMessage.GetType(), out var tcs))
{
tcs.SetResult(serviceMessage);
}
else
{
throw new InvalidOperationException("Not expected to write before tcs is inited");
}

return Task.CompletedTask;
}

Expand All @@ -44,7 +51,13 @@ public override Task WriteAsync(string partitionKey, ServiceMessage serviceMessa

public Task WaitForTransportOutputMessageAsync(Type messageType)
{
var tcs = _waitForTransportOutputMessage[messageType] = new TaskCompletionSource<ServiceMessage>();
if (_waitForTransportOutputMessage.TryGetValue(messageType, out var tcs))
{
tcs.TrySetCanceled();
}

// re-init the tcs
tcs = _waitForTransportOutputMessage[messageType] = new TaskCompletionSource<ServiceMessage>();

return tcs.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ public async Task ServiceConnectionDispatchTest()

// Application layer sends OpenConnectionMessage
var openConnectionMessage = new OpenConnectionMessage(clientConnection, new Claim[0], null, "?transport=webSockets");
var task = proxy.WaitForClientConnectAsync(clientConnection).OrTimeout();
await proxy.WriteMessageAsync(openConnectionMessage);
await proxy.WaitForClientConnectAsync(clientConnection).OrTimeout();
await task;

while (count < 1000)
{
task = proxy.WaitForApplicationMessageAsync(clientConnection).OrTimeout();
await proxy.WriteMessageAsync(new ConnectionDataMessage(clientConnection, GetPayload("Hello World")));
await proxy.WaitForApplicationMessageAsync(clientConnection).OrTimeout();
await task;
count++;
}

task = proxy.WaitForClientDisconnectAsync(clientConnection).OrTimeout();
await proxy.WriteMessageAsync(new CloseConnectionMessage(clientConnection));
await proxy.WaitForClientDisconnectAsync(clientConnection).OrTimeout();
await task;

// Validate in transport for 1000 data messages.
_clientConnectionManager.CurrentTransports.TryGetValue(clientConnection, out var transport);
Expand Down Expand Up @@ -113,8 +116,9 @@ public async Task ServiceConnectionDispatchGroupMessagesTest()
await lgTask;
await gbTask;

var dTask = proxy.WaitForClientDisconnectAsync(clientConnection).OrTimeout();
await proxy.WriteMessageAsync(new CloseConnectionMessage(clientConnection));
await proxy.WaitForClientDisconnectAsync(clientConnection).OrTimeout();
await dTask;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.AspNet.SignalR.Json;
using Microsoft.AspNet.SignalR.Messaging;
using Microsoft.AspNet.SignalR.Tracing;
using Microsoft.AspNet.SignalR.Transports;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Connections.Client;
using Microsoft.Azure.SignalR.Protocol;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Owin.Hosting;
using Newtonsoft.Json;
using Owin;
using Xunit;

namespace Microsoft.Azure.SignalR.AspNet.Tests
{
public class TraceManagerLoggerProviderTest
{
/// <summary>
/// TraceManagerLoggerProvider throws when its CreateLogger returns TraceSourceLogger when using HttpConnections.Client 1.0.0
/// </summary>
/// <returns></returns>
[Fact]
public async Task TestTraceManagerLoggerProviderCanDisposeHttpConnection()
{
var lf = new LoggerFactory();
lf.AddProvider(new TraceManagerLoggerProvider(new TraceManager()));
await StartAsync(lf);
}

private static async Task StartAsync(ILoggerFactory lf)
{
var connection = await ConnectAsync(lf);
// var connection = Connect(lf);
await ((HttpConnection)connection).DisposeAsync();
}

public static async Task<ConnectionContext> ConnectAsync(ILoggerFactory lf)
{
// Await to enforce it run in another thread
await Task.Yield();
var httpConnectionOptions = new HttpConnectionOptions
{
Url = new Uri("http://locolhost"),
};

return new HttpConnection(httpConnectionOptions, lf);
}
}
}

0 comments on commit fca8acb

Please sign in to comment.