From 8961024d5e1ca14c47564b3742ac9ec48845b6cb Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 25 Apr 2022 09:37:47 -0700 Subject: [PATCH 1/3] Update IISHttpContext.IO.cs --- src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs b/src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs index e8ca5be68676..9a456258161e 100644 --- a/src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs +++ b/src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs @@ -162,6 +162,11 @@ private async Task WriteBody(bool flush = false) var buffer = result.Buffer; try { + if (_bodyOutput.Aborted) + { + break; + } + if (!buffer.IsEmpty) { await AsyncIO!.WriteAsync(buffer); From f1425059843f15c43ac1ad394d2e2841c37c1fb2 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 25 Apr 2022 09:39:15 -0700 Subject: [PATCH 2/3] Update OutputProducer.cs --- src/Servers/IIS/IIS/src/Core/OutputProducer.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Servers/IIS/IIS/src/Core/OutputProducer.cs b/src/Servers/IIS/IIS/src/Core/OutputProducer.cs index 8bf887d1b86a..3b52dc8e284d 100644 --- a/src/Servers/IIS/IIS/src/Core/OutputProducer.cs +++ b/src/Servers/IIS/IIS/src/Core/OutputProducer.cs @@ -13,9 +13,10 @@ namespace Microsoft.AspNetCore.Server.IIS.Core { internal class OutputProducer { - // This locks access to _completed. + // This locks access to _completed and _aborted. private readonly object _contextLock = new object(); private bool _completed; + private volatile bool _aborted; private readonly Pipe _pipe; @@ -32,6 +33,8 @@ public OutputProducer(Pipe pipe) } public PipeReader Reader => _pipe.Reader; + + public bool Aborted => _aborted; public Task FlushAsync(CancellationToken cancellationToken) { @@ -44,7 +47,7 @@ public void Complete() { lock (_contextLock) { - if (_completed) + if (_completed || _aborted) { return; } @@ -58,12 +61,12 @@ public void Abort(Exception error) { lock (_contextLock) { - if (_completed) + if (_completed || _aborted) { return; } - _completed = true; + _aborted = true; _pipe.Reader.CancelPendingRead(); _pipe.Writer.Complete(); @@ -74,7 +77,7 @@ public Task WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellati { lock (_contextLock) { - if (_completed) + if (_completed || _aborted) { return Task.CompletedTask; } From 41ae77d1b0a9f027b1d41a3f82c217be8e2df08b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 25 Apr 2022 09:39:43 -0700 Subject: [PATCH 3/3] Update ResponseAbortTests.cs --- src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs b/src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs index 1cec8d64149f..9f8c1dbb6f9f 100644 --- a/src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs @@ -33,7 +33,6 @@ public async Task ClosesWithoutSendingAnything() } [ConditionalFact] - [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/31404")] public async Task ClosesAfterDataSent() { var bodyReceived = CreateTaskCompletionSource();