Skip to content

Commit 1c71752

Browse files
authored
Move connection id creation into the transport. (#11680)
1 parent d0d94e1 commit 1c71752

10 files changed

+28
-7
lines changed

src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public KestrelConnection(ConnectionContext connectionContext, ILogger logger)
2727
Logger = logger;
2828
TransportConnection = connectionContext;
2929

30-
// Set a connection id if the transport didn't set one
31-
TransportConnection.ConnectionId ??= CorrelationIdGenerator.GetNextId();
3230
connectionContext.Features.Set<IConnectionHeartbeatFeature>(this);
3331
connectionContext.Features.Set<IConnectionCompleteFeature>(this);
3432
connectionContext.Features.Set<IConnectionLifetimeNotificationFeature>(this);

src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1515
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
1616
<Compile Include="$(KestrelSharedSourceRoot)\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
17+
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
1718
</ItemGroup>
1819

1920
<ItemGroup>

src/Servers/Kestrel/Core/test/StringUtilitiesTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Connections;
45
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
56
using Xunit;
67

src/Servers/Kestrel/Transport.Libuv/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
15+
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
1516
<Compile Include="$(KestrelSharedSourceRoot)\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
1617
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.cs" Link="Internal\TransportConnection.cs" />
1718
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.Generated.cs" Link="Internal\TransportConnection.Generated.cs" />

src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
15+
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
1516
<Compile Include="$(KestrelSharedSourceRoot)\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
1617
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.cs" Link="Internal\TransportConnection.cs" />
1718
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.Generated.cs" Link="Internal\TransportConnection.Generated.cs" />

src/Servers/Kestrel/perf/Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Compile Include="$(KestrelSharedSourceRoot)test\TestHttp1Connection.cs" />
1616
<Compile Include="$(KestrelSharedSourceRoot)test\TestKestrelTrace.cs" />
1717
<Compile Include="..\..\Transport.Sockets\src\Internal\IOQueue.cs" Link="Internal\IOQueue.cs" />
18+
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
1819
<Compile Include="$(KestrelSharedSourceRoot)\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
1920
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.cs" Link="Internal\TransportConnection.cs" />
2021
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.Generated.cs" Link="Internal\TransportConnection.Generated.cs" />

src/Servers/Kestrel/perf/Kestrel.Performance/StringUtilitiesBenchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using BenchmarkDotNet.Attributes;
5+
using Microsoft.AspNetCore.Connections;
56
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
67

78
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Threading;
66

7-
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
7+
namespace Microsoft.AspNetCore.Connections
88
{
99
internal static class CorrelationIdGenerator
1010
{

src/Servers/Kestrel/shared/TransportConnection.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.Connections
1414
internal abstract partial class TransportConnection : ConnectionContext
1515
{
1616
private IDictionary<object, object> _items;
17+
private string _connectionId;
1718

1819
public TransportConnection()
1920
{
@@ -23,12 +24,27 @@ public TransportConnection()
2324
public override EndPoint LocalEndPoint { get; set; }
2425
public override EndPoint RemoteEndPoint { get; set; }
2526

26-
public override string ConnectionId { get; set; }
27+
public override string ConnectionId
28+
{
29+
get
30+
{
31+
if (_connectionId == null)
32+
{
33+
_connectionId = CorrelationIdGenerator.GetNextId();
34+
}
35+
36+
return _connectionId;
37+
}
38+
set
39+
{
40+
_connectionId = value;
41+
}
42+
}
2743

2844
public override IFeatureCollection Features => this;
2945

3046
public virtual MemoryPool<byte> MemoryPool { get; }
31-
47+
3248
public override IDuplexPipe Transport { get; set; }
3349

3450
public IDuplexPipe Application { get; set; }

src/Servers/Kestrel/test/InMemory.FunctionalTests/InMemory.FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<Compile Include="$(SharedSourceRoot)test\SkipOnHelixAttribute.cs" />
1414
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1515
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
16+
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
1617
<Compile Include="$(KestrelSharedSourceRoot)\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
1718
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.cs" Link="Internal\TransportConnection.cs" />
1819
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.Generated.cs" Link="Internal\TransportConnection.Generated.cs" />

0 commit comments

Comments
 (0)