diff --git a/src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.IO.cs b/src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.IO.cs index bfe44d634c..e945500672 100644 --- a/src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.IO.cs +++ b/src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.IO.cs @@ -184,11 +184,11 @@ namespace Microsoft.AspNetCore.Server.IIS.Core } } - private void AbortIO() + private bool AbortIO() { if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) != 0) { - return; + return false; } _bodyOutput.Dispose(); @@ -208,6 +208,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core } }); } + + return true; } public void Abort(Exception reason) @@ -221,8 +223,10 @@ namespace Microsoft.AspNetCore.Server.IIS.Core internal void ConnectionReset() { - AbortIO(); - Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId); + if (AbortIO()) + { + Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId); + } } } } diff --git a/src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.cs b/src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.cs index e7a01b331d..f169cebf77 100644 --- a/src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.cs +++ b/src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.cs @@ -52,7 +52,9 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO { if (_stopped) { - throw new IOException("IO stopped", NativeMethods.ERROR_OPERATION_ABORTED); + // Abort all operation after IO was stopped + ioOperation.Complete(NativeMethods.ERROR_OPERATION_ABORTED, 0); + return; } if (_runningOperation != null) diff --git a/test/IIS.Tests/ClientDisconnectTests.cs b/test/IIS.Tests/ClientDisconnectTests.cs index d8c7d4ef89..dbe562aa7c 100644 --- a/test/IIS.Tests/ClientDisconnectTests.cs +++ b/test/IIS.Tests/ClientDisconnectTests.cs @@ -2,13 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; -using Microsoft.Extensions.Logging.Testing; using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests @@ -207,8 +205,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests } Assert.IsType(exception); } - - AssertConnectionDisconnectLog(); } [ConditionalFact] @@ -289,7 +285,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private void AssertConnectionDisconnectLog() { - Assert.Contains(TestSink.Writes, w => w.EventId.Name == "ConnectionDisconnect"); + Assert.Single(TestSink.Writes, w => w.EventId.Name == "ConnectionDisconnect"); } private static async Task SendContentLength1Post(TestConnection connection) diff --git a/test/IIS.Tests/TestServerTest.cs b/test/IIS.Tests/TestServerTest.cs index c168af99d8..40b538ea52 100644 --- a/test/IIS.Tests/TestServerTest.cs +++ b/test/IIS.Tests/TestServerTest.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { [SkipIfHostableWebCoreNotAvailable] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, "https://github.com/aspnet/IISIntegration/issues/866")] - public class TestServerTest : LoggedTest + public class TestServerTest : StrictTestServerTests { [ConditionalFact] public async Task SingleProcessTestServer_HelloWorld()