Obsolete the Libuv transport (#23480)

This commit is contained in:
Kevin Pilch 2020-06-29 19:36:14 -07:00 committed by GitHub
parent 34a114530d
commit 197f156fcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 52 additions and 0 deletions

View File

@ -63,17 +63,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests
[Fact]
public void LibuvTransportCanBeManuallySelectedIndependentOfOrder()
{
#pragma warning disable CS0618
var hostBuilder = new WebHostBuilder()
.UseKestrel()
.UseLibuv()
.Configure(app => { });
#pragma warning restore CS0618
Assert.IsType<LibuvTransportFactory>(hostBuilder.Build().Services.GetService<IConnectionListenerFactory>());
#pragma warning disable CS0618
var hostBuilderReversed = new WebHostBuilder()
.UseLibuv()
.UseKestrel()
.Configure(app => { });
#pragma warning restore CS0618
Assert.IsType<LibuvTransportFactory>(hostBuilderReversed.Build().Services.GetService<IConnectionListenerFactory>());
}

View File

@ -40,7 +40,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
public IHostApplicationLifetime AppLifetime => TransportContext.AppLifetime;
public ILibuvTrace Log => TransportContext.Log;
#pragma warning disable CS0618
public LibuvTransportOptions TransportOptions => TransportContext.Options;
#pragma warning restore CS0618
public EndPoint EndPoint { get; set; }
@ -131,7 +134,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
// TODO: Move thread management to LibuvTransportFactory
// TODO: Split endpoint management from thread management
#pragma warning disable CS0618
for (var index = 0; index < TransportOptions.ThreadCount; index++)
#pragma warning restore CS0618
{
Threads.Add(new LibuvThread(Libuv, TransportContext));
}
@ -143,7 +148,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
try
{
#pragma warning disable CS0618
if (TransportOptions.ThreadCount == 1)
#pragma warning restore CS0618
{
var listener = new Listener(TransportContext);
_listeners.Add(listener);

View File

@ -7,7 +7,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
internal class LibuvTransportContext
{
#pragma warning disable CS0618
public LibuvTransportOptions Options { get; set; }
#pragma warning restore CS0618
public IHostApplicationLifetime AppLifetime { get; set; }

View File

@ -17,7 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
private readonly LibuvTransportContext _baseTransportContext;
public LibuvTransportFactory(
#pragma warning disable CS0618
IOptions<LibuvTransportOptions> options,
#pragma warning restore CS0618
IHostApplicationLifetime applicationLifetime,
ILoggerFactory loggerFactory)
{
@ -37,7 +39,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv");
var trace = new LibuvTrace(logger);
#pragma warning disable CS0618
var threadCount = options.Value.ThreadCount;
#pragma warning restore CS0618
if (threadCount <= 0)
{

View File

@ -37,7 +37,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
return Thread.PostAsync(listener =>
{
listener.ListenSocket = listener.CreateListenSocket();
#pragma warning disable CS0618
listener.ListenSocket.Listen(TransportContext.Options.Backlog, ConnectionCallback, listener);
#pragma warning restore CS0618
}, this);
}
@ -66,7 +68,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
try
{
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
#pragma warning disable CS0618
socket.NoDelay(TransportContext.Options.NoDelay);
#pragma warning restore CS0618
if (!useFileHandle)
{

View File

@ -109,7 +109,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
}
var options = TransportContext.Options;
#pragma warning disable CS0618
var connection = new LibuvConnection(socket, TransportContext.Log, Thread, remoteEndPoint, localEndPoint, InputOptions, OutputOptions, options.MaxReadBufferSize, options.MaxWriteBufferSize);
#pragma warning restore CS0618
connection.Start();
bool accepted = _acceptQueue.Writer.TryWrite(connection);
@ -128,7 +130,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
try
{
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
#pragma warning disable CS0618
socket.NoDelay(TransportContext.Options.NoDelay);
#pragma warning restore CS0618
}
catch
{

View File

@ -69,8 +69,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
ListenPipe = new UvPipeHandle(Log);
ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false);
ListenPipe.Bind(_pipeName);
#pragma warning disable CS0618
ListenPipe.Listen(TransportContext.Options.Backlog,
(pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this);
#pragma warning restore CS0618
}
private void OnListenPipe(UvStreamHandle pipe, int status, UvException error)

View File

@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
/// <summary>
/// Provides programmatic configuration of Libuv transport features.
/// </summary>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public class LibuvTransportOptions
{
/// <summary>
@ -17,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
/// <remarks>
/// Defaults to half of <see cref="Environment.ProcessorCount" /> rounded down and clamped between 1 and 16.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public int ThreadCount { get; set; } = ProcessorThreadCount;
/// <summary>
@ -25,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
/// <remarks>
/// Defaults to true.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public bool NoDelay { get; set; } = true;
/// <summary>
@ -33,10 +36,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
/// <remarks>
/// Defaults to 128.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public int Backlog { get; set; } = 128;
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public long? MaxReadBufferSize { get; set; } = 1024 * 1024;
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public long? MaxWriteBufferSize { get; set; } = 64 * 1024;
internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create;

View File

@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static class WebHostBuilderLibuvExtensions
{
/// <summary>
@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Hosting
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices(services =>
@ -40,6 +42,7 @@ namespace Microsoft.AspNetCore.Hosting
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder, Action<LibuvTransportOptions> configureOptions)
{
return hostBuilder.UseLibuv().ConfigureServices(services =>

View File

@ -18,7 +18,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
[InlineData(-1337)]
public void StartWithNonPositiveThreadCountThrows(int threadCount)
{
#pragma warning disable CS0618
var options = new LibuvTransportOptions { ThreadCount = threadCount };
#pragma warning restore CS0618
var exception = Assert.Throws<ArgumentOutOfRangeException>(() =>
new LibuvTransportFactory(Options.Create(options), new LifetimeNotImplemented(), Mock.Of<ILoggerFactory>()));
@ -30,7 +32,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
public void LoggerCategoryNameIsLibuvTransportNamespace()
{
var mockLoggerFactory = new Mock<ILoggerFactory>();
#pragma warning disable CS0618
new LibuvTransportFactory(Options.Create<LibuvTransportOptions>(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object);
#pragma warning restore CS0618
mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"));
}
}

View File

@ -14,9 +14,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
// Ideally we'd mock Environment.ProcessorCount to test edge cases.
var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16);
#pragma warning disable CS0618
var information = new LibuvTransportOptions();
Assert.Equal(expected, information.ThreadCount);
#pragma warning restore CS0618
}
private static int Clamp(int value, int min, int max)

View File

@ -191,7 +191,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var transportContext = new TestLibuvTransportContext
{
#pragma warning disable CS0618
Options = new LibuvTransportOptions { ThreadCount = threadCount }
#pragma warning restore CS0618
};
await using var transport = new LibuvConnectionListener(transportContext, listenOptions.EndPoint);

View File

@ -14,7 +14,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests.TestHelpers
AppLifetime = new LifetimeNotImplemented();
Log = new LibuvTrace(logger);
#pragma warning disable CS0618
Options = new LibuvTransportOptions { ThreadCount = 1 };
#pragma warning restore CS0618
}
}
}

View File

@ -157,11 +157,13 @@ namespace SampleApp
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
{
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
#pragma warning disable CS0618
hostBuilder.UseLibuv(options =>
{
// Uncomment the following line to change the default number of libuv threads for all endpoints.
// options.ThreadCount = 4;
});
#pragma warning restore CS0618
}
return hostBuilder.Build().RunAsync();

View File

@ -75,11 +75,13 @@ namespace SystemdTestApp
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
{
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
#pragma warning disable CS0618
hostBuilder.UseLibuv(options =>
{
// Uncomment the following line to change the default number of libuv threads for all endpoints.
// options.ThreadCount = 4;
});
#pragma warning restore CS0618
}
return hostBuilder.Build().RunAsync();

View File

@ -12,11 +12,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
public static IWebHostBuilder GetWebHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
long? maxReadBufferSize = null)
{
#pragma warning disable CS0618
return new WebHostBuilder().UseLibuv(options =>
{
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
options.MaxReadBufferSize = maxReadBufferSize;
});
#pragma warning restore CS0618
}
}
}