Skip to content

Commit b1d2844

Browse files
authored
release/6.0 port of abort handling (#41360)
1 parent 9b36c67 commit b1d2844

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ private async Task WriteBody(bool flush = false)
162162
var buffer = result.Buffer;
163163
try
164164
{
165+
if (_bodyOutput.Aborted)
166+
{
167+
break;
168+
}
169+
165170
if (!buffer.IsEmpty)
166171
{
167172
await AsyncIO!.WriteAsync(buffer);

src/Servers/IIS/IIS/src/Core/OutputProducer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
1313
{
1414
internal class OutputProducer
1515
{
16-
// This locks access to _completed.
16+
// This locks access to _completed and _aborted.
1717
private readonly object _contextLock = new object();
1818
private bool _completed;
19+
private volatile bool _aborted;
1920

2021
private readonly Pipe _pipe;
2122

@@ -32,6 +33,8 @@ public OutputProducer(Pipe pipe)
3233
}
3334

3435
public PipeReader Reader => _pipe.Reader;
36+
37+
public bool Aborted => _aborted;
3538

3639
public Task FlushAsync(CancellationToken cancellationToken)
3740
{
@@ -44,7 +47,7 @@ public void Complete()
4447
{
4548
lock (_contextLock)
4649
{
47-
if (_completed)
50+
if (_completed || _aborted)
4851
{
4952
return;
5053
}
@@ -58,12 +61,12 @@ public void Abort(Exception error)
5861
{
5962
lock (_contextLock)
6063
{
61-
if (_completed)
64+
if (_completed || _aborted)
6265
{
6366
return;
6467
}
6568

66-
_completed = true;
69+
_aborted = true;
6770

6871
_pipe.Reader.CancelPendingRead();
6972
_pipe.Writer.Complete();
@@ -74,7 +77,7 @@ public Task WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellati
7477
{
7578
lock (_contextLock)
7679
{
77-
if (_completed)
80+
if (_completed || _aborted)
7881
{
7982
return Task.CompletedTask;
8083
}

src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public async Task ClosesWithoutSendingAnything()
3333
}
3434

3535
[ConditionalFact]
36-
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/31404")]
3736
public async Task ClosesAfterDataSent()
3837
{
3938
var bodyReceived = CreateTaskCompletionSource();

0 commit comments

Comments
 (0)