diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionManager.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionManager.cs index eb20cbac19..05bb0f0726 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionManager.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionManager.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure Walk(connection => { - connection.GetTransport().Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown)); + connection.TransportConnection.Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown)); abortTasks.Add(connection.ExecutionTask); }); diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionReference.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionReference.cs index 5e1702b7a6..dd31fde12f 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionReference.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/ConnectionReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure public ConnectionReference(KestrelConnection connection) { _weakReference = new WeakReference(connection); - ConnectionId = connection.GetTransport().ConnectionId; + ConnectionId = connection.TransportConnection.ConnectionId; } public string ConnectionId { get; } diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs index ecb09f1784..5365ed7397 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } } - public abstract BaseConnectionContext GetTransport(); + public abstract BaseConnectionContext TransportConnection { get; } public void OnHeartbeat(Action action, object state) { diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnectionOfT.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnectionOfT.cs index 5da4997177..d758bf3f1a 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnectionOfT.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnectionOfT.cs @@ -10,8 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure internal class KestrelConnection : KestrelConnection, IThreadPoolWorkItem where T : BaseConnectionContext { private readonly Func _connectionDelegate; - - public T TransportConnection { get; set; } + private readonly T _transportConnection; public KestrelConnection(long id, ServiceContext serviceContext, @@ -21,12 +20,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure : base(id, serviceContext, logger) { _connectionDelegate = connectionDelegate; - TransportConnection = connectionContext; + _transportConnection = connectionContext; connectionContext.Features.Set(this); connectionContext.Features.Set(this); connectionContext.Features.Set(this); } + public override BaseConnectionContext TransportConnection => _transportConnection; + void IThreadPoolWorkItem.Execute() { _ = ExecuteAsync(); @@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure internal async Task ExecuteAsync() { - var connectionContext = TransportConnection; + var connectionContext = _transportConnection; try { @@ -63,15 +64,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure // Dispose the transport connection, this needs to happen before removing it from the // connection manager so that we only signal completion of this connection after the transport // is properly torn down. - await TransportConnection.DisposeAsync(); + await connectionContext.DisposeAsync(); _serviceContext.ConnectionManager.RemoveConnection(_id); } } - - public override BaseConnectionContext GetTransport() - { - return TransportConnection; - } } } diff --git a/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs b/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs index b9b32bb521..33bba9c48e 100644 --- a/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs +++ b/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests connection.ConnectionClosed = new CancellationToken(canceled: true); var kestrelConnection = new KestrelConnection(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log); serviceContext.ConnectionManager.AddConnection(0, kestrelConnection); - var completeFeature = kestrelConnection.GetTransport().Features.Get(); + var completeFeature = kestrelConnection.TransportConnection.Features.Get(); Assert.NotNull(completeFeature); object stateObject = new object(); @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests connection.ConnectionClosed = new CancellationToken(canceled: true); var kestrelConnection = new KestrelConnection(0, serviceContext, _ => Task.CompletedTask, connection, serviceContext.Log); serviceContext.ConnectionManager.AddConnection(0, kestrelConnection); - var completeFeature = kestrelConnection.GetTransport().Features.Get(); + var completeFeature = kestrelConnection.TransportConnection.Features.Get(); Assert.NotNull(completeFeature); object stateObject = new object();