From 197f156fcd5bb976a9b0517078ffc27fae2e4bd3 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Mon, 29 Jun 2020 19:36:14 -0700 Subject: [PATCH] Obsolete the Libuv transport (#23480) --- .../Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs | 4 ++++ .../src/Internal/LibuvConnectionListener.cs | 7 +++++++ .../Transport.Libuv/src/Internal/LibuvTransportContext.cs | 2 ++ .../Transport.Libuv/src/Internal/LibuvTransportFactory.cs | 4 ++++ .../Kestrel/Transport.Libuv/src/Internal/Listener.cs | 4 ++++ .../Transport.Libuv/src/Internal/ListenerContext.cs | 4 ++++ .../Transport.Libuv/src/Internal/ListenerPrimary.cs | 2 ++ .../Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs | 6 ++++++ .../Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs | 3 +++ .../Transport.Libuv/test/LibuvTransportFactoryTests.cs | 4 ++++ .../Transport.Libuv/test/LibuvTransportOptionsTests.cs | 2 ++ .../Kestrel/Transport.Libuv/test/LibuvTransportTests.cs | 2 ++ .../test/TestHelpers/TestLibuvTransportContext.cs | 2 ++ src/Servers/Kestrel/samples/SampleApp/Startup.cs | 2 ++ src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs | 2 ++ .../test/Libuv.FunctionalTests/TransportSelector.cs | 2 ++ 16 files changed, 52 insertions(+) diff --git a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs index fd5c31d032..6f2b8c9687 100644 --- a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs +++ b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs @@ -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(hostBuilder.Build().Services.GetService()); +#pragma warning disable CS0618 var hostBuilderReversed = new WebHostBuilder() .UseLibuv() .UseKestrel() .Configure(app => { }); +#pragma warning restore CS0618 Assert.IsType(hostBuilderReversed.Build().Services.GetService()); } diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnectionListener.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnectionListener.cs index d1b2e9a8e7..f023d5421a 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnectionListener.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnectionListener.cs @@ -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); diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs index 973a0fec06..4323463ef2 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs @@ -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; } diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs index 689c473195..2b168c0950 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs @@ -17,7 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal private readonly LibuvTransportContext _baseTransportContext; public LibuvTransportFactory( +#pragma warning disable CS0618 IOptions 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) { diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs index 6279764101..92c89456b1 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs @@ -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) { diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs index 528ec5ca3b..831da6ae8b 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs @@ -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 { diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs index 070ee5a73b..6db3e4bffc 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs @@ -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) diff --git a/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs b/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs index 0aa477f3af..ee96297f1d 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs @@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv /// /// Provides programmatic configuration of Libuv transport features. /// + [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 { /// @@ -17,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv /// /// Defaults to half of rounded down and clamped between 1 and 16. /// + [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; /// @@ -25,6 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv /// /// Defaults to true. /// + [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; /// @@ -33,10 +36,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv /// /// Defaults to 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 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> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; diff --git a/src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs b/src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs index 8f0986d334..fc795fcde4 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/WebHostBuilderLibuvExtensions.cs @@ -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 { /// @@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Hosting /// /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. /// + [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 /// /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. /// + [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 configureOptions) { return hostBuilder.UseLibuv().ConfigureServices(services => diff --git a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs index 60d8f55dc6..b1230babdb 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportFactoryTests.cs @@ -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(() => new LibuvTransportFactory(Options.Create(options), new LifetimeNotImplemented(), Mock.Of())); @@ -30,7 +32,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests public void LoggerCategoryNameIsLibuvTransportNamespace() { var mockLoggerFactory = new Mock(); +#pragma warning disable CS0618 new LibuvTransportFactory(Options.Create(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object); +#pragma warning restore CS0618 mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv")); } } diff --git a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs index 8651bdb2ff..aa6b705047 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportOptionsTests.cs @@ -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) diff --git a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs index 12f802864d..b7d1e16fd5 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/LibuvTransportTests.cs @@ -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); diff --git a/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs index 1bccf57d32..a2d49bc8d0 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/TestLibuvTransportContext.cs @@ -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 } } } diff --git a/src/Servers/Kestrel/samples/SampleApp/Startup.cs b/src/Servers/Kestrel/samples/SampleApp/Startup.cs index 3b61d0fe91..6f6afe3fac 100644 --- a/src/Servers/Kestrel/samples/SampleApp/Startup.cs +++ b/src/Servers/Kestrel/samples/SampleApp/Startup.cs @@ -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(); diff --git a/src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs b/src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs index 56e6f3f980..8a01fac6d9 100644 --- a/src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs +++ b/src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs @@ -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(); diff --git a/src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs b/src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs index 4bcae2a6cf..4bd8e32597 100644 --- a/src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs +++ b/src/Servers/Kestrel/test/Libuv.FunctionalTests/TransportSelector.cs @@ -12,11 +12,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests public static IWebHostBuilder GetWebHostBuilder(Func> 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 } } }