From 34ab089e7bd5f17f4a3ccf6e80f39810fe84fb7e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 18 May 2017 14:49:48 -0700 Subject: [PATCH] React to scheduler changes (#1846) --- .../Infrastructure/InlineLoggingThreadPool.cs | 11 +++++++++-- .../Internal/Infrastructure/LoggingThreadPool.cs | 6 +++--- .../Internal/LibuvThread.cs | 4 ++-- .../LibuvConnectionTests.cs | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs index 0160b59590..f762ff976b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/InlineLoggingThreadPool.cs @@ -33,9 +33,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure action(state); } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Run(action); + try + { + action(state); + } + catch (Exception e) + { + _log.LogError(0, e, "InlineLoggingThreadPool.Schedule"); + } } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs index 1718967c50..184d956b18 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Infrastructure/LoggingThreadPool.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure _log = log; // Curry and capture log in closures once - // The currying is done in functions of the same name to improve the + // The currying is done in functions of the same name to improve the // call stack for exceptions and profiling else it shows up as LoggingThreadPool.ctor>b__4_0 // and you aren't sure which of the 3 functions was called. RunAction(); @@ -50,9 +50,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure ThreadPool.QueueUserWorkItem(action, state); } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Run(action); + Run(() => action(state)); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index bc3e0139c5..299fffef7c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -383,9 +383,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; } - public void Schedule(Action action) + public void Schedule(Action action, object state) { - Post(state => state(), action); + Post(action, state); } private struct Work diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs index 7034a65711..de27f5774d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvConnectionTests.cs @@ -114,9 +114,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var thread = new LibuvThread(transport); var mockScheduler = new Mock(); Action backPressure = null; - mockScheduler.Setup(m => m.Schedule(It.IsAny())).Callback(a => + mockScheduler.Setup(m => m.Schedule(It.IsAny>(), It.IsAny())).Callback, object>((a, o) => { - backPressure = a; + backPressure = () => a(o); }); mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object; mockConnectionHandler.OutputOptions.ReaderScheduler = thread;