Clean up some remants of the past (#2827)

- Remove Application from HttpConnectionContext and Http*ConnectionContext (it's no longer required)
This commit is contained in:
David Fowler 2018-08-15 23:41:32 -07:00 committed by GitHub
parent 5becb72107
commit 83488886e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 46 additions and 59 deletions

View File

@ -43,7 +43,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ConnectionFeatures = new FeatureCollection(),
MemoryPool = memoryPool,
TimeoutControl = new MockTimeoutControl(),
Application = pair.Application,
Transport = pair.Transport
});

View File

@ -39,7 +39,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ConnectionFeatures = new FeatureCollection(),
MemoryPool = memoryPool,
TimeoutControl = new MockTimeoutControl(),
Application = pair.Application,
Transport = pair.Transport
});

View File

@ -113,7 +113,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(),
MemoryPool = _memoryPool,
Application = pair.Application,
Transport = pair.Transport
});

View File

@ -96,7 +96,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(),
MemoryPool = memoryPool,
Application = pair.Application,
Transport = pair.Transport
});

View File

@ -41,7 +41,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(),
MemoryPool = _memoryPool,
Application = pair.Application,
Transport = pair.Transport,
TimeoutControl = new MockTimeoutControl()
});

View File

@ -188,7 +188,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(),
MemoryPool = memoryPool,
Application = pair.Application,
Transport = pair.Transport
});

View File

@ -133,7 +133,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
ConnectionFeatures = new FeatureCollection(),
MemoryPool = _memoryPool,
TimeoutControl = new MockTimeoutControl(),
Application = _pair.Application,
Transport = _pair.Transport
});

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Threading;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Connections
{
// We expect this to be overridden, but this helps maintain back compat
// with implementations of ConnectionContext that predate the addition of
// ConnectioContext.Abort()
// ConnectionContext.Abort()
Features.Get<IConnectionLifetimeFeature>()?.Abort();
}

View File

@ -168,9 +168,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal
_transport.Input.Complete();
}
}
public void Dispose()
{
}
}
}

View File

@ -21,6 +21,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
public IPEndPoint LocalEndPoint { get; set; }
public ITimeoutControl TimeoutControl { get; set; }
public IDuplexPipe Transport { get; set; }
public IDuplexPipe Application { get; set; }
}
}

View File

@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
public Http2Connection(Http2ConnectionContext context)
{
_context = context;
_frameWriter = new Http2FrameWriter(context.Transport.Output, context.Application.Input, _outputFlowControl, this, context.ConnectionId, context.ServiceContext.Log);
_frameWriter = new Http2FrameWriter(context.Transport.Output, context.ConnectionContext, _outputFlowControl, this, context.ConnectionId, context.ServiceContext.Log);
_hpackDecoder = new HPackDecoder((int)_serverSettings.HeaderTableSize);
_serverSettings.MaxConcurrentStreams = (uint)context.ServiceContext.ServerOptions.Limits.Http2.MaxStreamsPerConnection;
}

View File

@ -4,6 +4,7 @@
using System.Buffers;
using System.IO.Pipelines;
using System.Net;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
@ -11,13 +12,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
public class Http2ConnectionContext
{
public string ConnectionId { get; set; }
public ConnectionContext ConnectionContext { get; set; }
public ServiceContext ServiceContext { get; set; }
public IFeatureCollection ConnectionFeatures { get; set; }
public MemoryPool<byte> MemoryPool { get; set; }
public IPEndPoint LocalEndPoint { get; set; }
public IPEndPoint RemoteEndPoint { get; set; }
public IDuplexPipe Transport { get; set; }
public IDuplexPipe Application { get; set; }
}
}

View File

@ -26,7 +26,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
private readonly object _writeLock = new object();
private readonly HPackEncoder _hpackEncoder = new HPackEncoder();
private readonly PipeWriter _outputWriter;
private readonly PipeReader _outputReader;
private bool _aborted;
private readonly ConnectionContext _connectionContext;
private readonly OutputFlowControl _connectionOutputFlowControl;
private readonly string _connectionId;
private readonly IKestrelTrace _log;
@ -36,15 +37,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
public Http2FrameWriter(
PipeWriter outputPipeWriter,
PipeReader outputPipeReader,
ConnectionContext connectionContext,
OutputFlowControl connectionOutputFlowControl,
ITimeoutControl timeoutControl,
string connectionId,
IKestrelTrace log)
{
_outputWriter = outputPipeWriter;
_outputReader = outputPipeReader;
_connectionContext = connectionContext;
_connectionOutputFlowControl = connectionOutputFlowControl;
_connectionId = connectionId;
_log = log;
@ -66,11 +66,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
}
}
public void Abort(ConnectionAbortedException ex)
public void Abort(ConnectionAbortedException error)
{
// TODO: Really abort the connection using the ConnectionContex like Http1OutputProducer.
_outputReader.CancelPendingRead();
Complete();
lock (_writeLock)
{
if (_aborted)
{
return;
}
_aborted = true;
_connectionContext.Abort(error);
Complete();
}
}
public Task FlushAsync(IHttpOutputProducer outputProducer, CancellationToken cancellationToken)
@ -239,7 +248,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
}
// This awaitable releases continuations in FIFO order when the window updates.
// It should be very rare for a continuation to run without any availability.
// It should be very rare for a continuation to run without any availability.
if (availabilityAwaitable != null)
{
await availabilityAwaitable;

View File

@ -112,7 +112,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
// _adaptedTransport must be set prior to adding the connection to the manager in order
// to allow the connection to be aported prior to protocol selection.
_adaptedTransport = _context.Transport;
var application = _context.Application;
if (_context.ConnectionAdapters.Count > 0)
@ -147,14 +146,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
{
case HttpProtocols.Http1:
// _http1Connection must be initialized before adding the connection to the connection manager
requestProcessor = _http1Connection = CreateHttp1Connection(_adaptedTransport, application);
requestProcessor = _http1Connection = CreateHttp1Connection(_adaptedTransport);
_protocolSelectionState = ProtocolSelectionState.Selected;
break;
case HttpProtocols.Http2:
// _http2Connection must be initialized before yielding control to the transport thread,
// to prevent a race condition where _http2Connection.Abort() is called just as
// _http2Connection is about to be initialized.
requestProcessor = CreateHttp2Connection(_adaptedTransport, application);
requestProcessor = CreateHttp2Connection(_adaptedTransport);
_protocolSelectionState = ProtocolSelectionState.Selected;
break;
case HttpProtocols.None:
@ -199,13 +198,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
}
// For testing only
internal void Initialize(IDuplexPipe transport, IDuplexPipe application)
internal void Initialize(IDuplexPipe transport)
{
_requestProcessor = _http1Connection = CreateHttp1Connection(transport, application);
_requestProcessor = _http1Connection = CreateHttp1Connection(transport);
_protocolSelectionState = ProtocolSelectionState.Selected;
}
private Http1Connection CreateHttp1Connection(IDuplexPipe transport, IDuplexPipe application)
private Http1Connection CreateHttp1Connection(IDuplexPipe transport)
{
return new Http1Connection(new Http1ConnectionContext
{
@ -217,22 +216,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
ServiceContext = _context.ServiceContext,
ConnectionContext = _context.ConnectionContext,
TimeoutControl = this,
Transport = transport,
Application = application
Transport = transport
});
}
private Http2Connection CreateHttp2Connection(IDuplexPipe transport, IDuplexPipe application)
private Http2Connection CreateHttp2Connection(IDuplexPipe transport)
{
return new Http2Connection(new Http2ConnectionContext
{
ConnectionId = _context.ConnectionId,
ConnectionContext = _context.ConnectionContext,
ServiceContext = _context.ServiceContext,
ConnectionFeatures = _context.ConnectionFeatures,
MemoryPool = MemoryPool,
LocalEndPoint = LocalEndPoint,
RemoteEndPoint = RemoteEndPoint,
Application = application,
Transport = transport
});
}

View File

@ -24,6 +24,5 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
public IPEndPoint LocalEndPoint { get; set; }
public IPEndPoint RemoteEndPoint { get; set; }
public IDuplexPipe Transport { get; set; }
public IDuplexPipe Application { get; set; }
}
}

View File

@ -37,7 +37,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
{
// We need the transport feature so that we can cancel the output reader that the transport is using
// This is a bit of a hack but it preserves the existing semantics
var applicationFeature = connectionContext.Features.Get<IApplicationTransportFeature>();
var memoryPoolFeature = connectionContext.Features.Get<IMemoryPoolFeature>();
var httpConnectionId = Interlocked.Increment(ref _lastHttpConnectionId);
@ -52,8 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
ConnectionFeatures = connectionContext.Features,
MemoryPool = memoryPoolFeature.MemoryPool,
ConnectionAdapters = _connectionAdapters,
Transport = connectionContext.Transport,
Application = applicationFeature.Application
Transport = connectionContext.Transport
};
var connectionFeature = connectionContext.Features.Get<IHttpConnectionFeature>();

View File

@ -63,7 +63,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ConnectionFeatures = connectionFeatures,
MemoryPool = _pipelineFactory,
TimeoutControl = _timeoutControl.Object,
Application = pair.Application,
Transport = pair.Transport
};

View File

@ -44,7 +44,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ConnectionFeatures = connectionFeatures,
MemoryPool = _memoryPool,
HttpConnectionId = long.MinValue,
Application = pair.Application,
Transport = pair.Transport,
ServiceContext = new TestServiceContext
{
@ -66,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockDebugger = new Mock<IDebugger>();
mockDebugger.SetupGet(g => g.IsAttached).Returns(true);
_httpConnection.Debugger = mockDebugger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
var now = DateTimeOffset.Now;
_httpConnection.Tick(now);
@ -113,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
_httpConnectionContext.ServiceContext.Log = logger;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
// Initialize timestamp
@ -140,7 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
// Initialize timestamp
@ -182,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
// Initialize timestamp
@ -259,7 +258,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
// Initialize timestamp
@ -327,7 +326,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
// Initialize timestamp
@ -389,7 +388,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
var startTime = systemClock.UtcNow;
@ -430,7 +429,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
_httpConnection.Http1Connection.RequestAborted.Register(() =>
{
@ -464,7 +463,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
_httpConnection.Http1Connection.RequestAborted.Register(() =>
{
@ -506,7 +505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
_httpConnection.Http1Connection.RequestAborted.Register(() =>
{
@ -555,7 +554,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var mockLogger = new Mock<IKestrelTrace>();
_httpConnectionContext.ServiceContext.Log = mockLogger.Object;
_httpConnection.Initialize(_httpConnectionContext.Transport, _httpConnectionContext.Application);
_httpConnection.Initialize(_httpConnectionContext.Transport);
_httpConnection.Http1Connection.Reset();
_httpConnection.Http1Connection.RequestAborted.Register(() =>
{

View File

@ -46,7 +46,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ConnectionFeatures = new FeatureCollection(),
MemoryPool = _memoryPool,
TimeoutControl = _timeoutControl.Object,
Application = pair.Application,
Transport = pair.Transport
};

View File

@ -30,7 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ServiceContext = new TestServiceContext(),
ConnectionFeatures = new FeatureCollection(),
MemoryPool = memoryPool,
Application = pair.Application,
Transport = pair.Transport,
TimeoutControl = null
};

View File

@ -422,12 +422,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var options = new PipeOptions(pool: memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
var pair = DuplexPipe.CreateConnectionPair(options, options);
var transport = pair.Transport;
var application = pair.Application;
var http1ConnectionContext = new Http1ConnectionContext
{
ServiceContext = new TestServiceContext(),
ConnectionFeatures = new FeatureCollection(),
Application = application,
Transport = transport,
MemoryPool = memoryPool,
TimeoutControl = Mock.Of<ITimeoutControl>()

View File

@ -38,7 +38,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ServiceContext = new TestServiceContext(),
ConnectionContext = Mock.Of<ConnectionContext>(),
ConnectionFeatures = connectionFeatures,
Application = Application,
Transport = Transport,
MemoryPool = _memoryPool,
TimeoutControl = Mock.Of<ITimeoutControl>()

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests

View File

@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Connections;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
@ -280,10 +281,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
_connectionContext = new Http2ConnectionContext
{
ConnectionContext = Mock.Of<ConnectionContext>(),
ConnectionFeatures = new FeatureCollection(),
ServiceContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object),
MemoryPool = _memoryPool,
Application = _pair.Application,
Transport = _pair.Transport
};

View File

@ -743,7 +743,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
ConnectionFeatures = connectionFeatures,
MemoryPool = _memoryPool,
TimeoutControl = Mock.Of<ITimeoutControl>(),
Application = pair.Application,
Transport = pair.Transport
});