diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs index ccb51230c54c..cfa274558c9f 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 @@ public KestrelConnection(ConnectionContext connectionContext, ILogger logger) 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 843f1b8e9336..52f05d352cc0 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 5ef5f30cc155..bc935f01f7e2 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 42a5a7943b1c..01e94867f2df 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 09398f57ac1d..278396fc1c92 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 0789bc504909..21200ecc81f9 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 e2b2e9eab18b..17be1118fc23 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 a6c641d59429..c8aa7850e6df 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 48ec513a2237..3cf1c58c5f4b 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 @@ public TransportConnection() 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 3e6f1bcd6ad0..c00165c4d433 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 @@ +