From 1c71752b1ff99bfd8dd70f54f127832a1645ae35 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 28 Jun 2019 10:00:05 -0700 Subject: [PATCH] Move connection id creation into the transport. (#11680) --- .../Infrastructure/KestrelConnection.cs | 2 -- ...spNetCore.Server.Kestrel.Core.Tests.csproj | 1 + .../Kestrel/Core/test/StringUtilitiesTests.cs | 3 ++- ...Core.Server.Kestrel.Transport.Libuv.csproj | 1 + ...re.Server.Kestrel.Transport.Sockets.csproj | 1 + ...pNetCore.Server.Kestrel.Performance.csproj | 1 + .../StringUtilitiesBenchmark.cs | 3 ++- .../CorrelationIdGenerator.cs | 2 +- .../Kestrel/shared/TransportConnection.cs | 20 +++++++++++++++++-- .../InMemory.FunctionalTests.csproj | 1 + 10 files changed, 28 insertions(+), 7 deletions(-) rename src/Servers/Kestrel/{Core/src/Internal/Infrastructure => shared}/CorrelationIdGenerator.cs (96%) diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs index ccb51230c5..cfa274558c 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs @@ -27,8 +27,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure Logger = logger; TransportConnection = connectionContext; - // Set a connection id if the transport didn't set one - TransportConnection.ConnectionId ??= CorrelationIdGenerator.GetNextId(); connectionContext.Features.Set(this); connectionContext.Features.Set(this); connectionContext.Features.Set(this); diff --git a/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj b/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj index 843f1b8e93..52f05d352c 100644 --- a/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj +++ b/src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs b/src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs index 5ef5f30cc1..bc935f01f7 100644 --- a/src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs +++ b/src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs @@ -1,6 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Xunit; diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj b/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj index 42a5a7943b..01e94867f2 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj +++ b/src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index 09398f57ac..278396fc1c 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 0789bc5049..21200ecc81 100644 --- a/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs b/src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs index e2b2e9eab1..17be1118fc 100644 --- a/src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs +++ b/src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs @@ -1,7 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/CorrelationIdGenerator.cs b/src/Servers/Kestrel/shared/CorrelationIdGenerator.cs similarity index 96% rename from src/Servers/Kestrel/Core/src/Internal/Infrastructure/CorrelationIdGenerator.cs rename to src/Servers/Kestrel/shared/CorrelationIdGenerator.cs index a6c641d594..c8aa7850e6 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/CorrelationIdGenerator.cs +++ b/src/Servers/Kestrel/shared/CorrelationIdGenerator.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure +namespace Microsoft.AspNetCore.Connections { internal static class CorrelationIdGenerator { diff --git a/src/Servers/Kestrel/shared/TransportConnection.cs b/src/Servers/Kestrel/shared/TransportConnection.cs index 48ec513a22..3cf1c58c5f 100644 --- a/src/Servers/Kestrel/shared/TransportConnection.cs +++ b/src/Servers/Kestrel/shared/TransportConnection.cs @@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.Connections internal abstract partial class TransportConnection : ConnectionContext { private IDictionary _items; + private string _connectionId; public TransportConnection() { @@ -23,12 +24,27 @@ namespace Microsoft.AspNetCore.Connections public override EndPoint LocalEndPoint { get; set; } public override EndPoint RemoteEndPoint { get; set; } - public override string ConnectionId { get; set; } + public override string ConnectionId + { + get + { + if (_connectionId == null) + { + _connectionId = CorrelationIdGenerator.GetNextId(); + } + + return _connectionId; + } + set + { + _connectionId = value; + } + } public override IFeatureCollection Features => this; public virtual MemoryPool MemoryPool { get; } - + public override IDuplexPipe Transport { get; set; } public IDuplexPipe Application { get; set; } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj b/src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj index 3e6f1bcd6a..c00165c4d4 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj @@ -13,6 +13,7 @@ +