Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/6.0 port of abort handling #41360

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Servers/IIS/IIS/src/Core/IISHttpContext.IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions src/Servers/IIS/IIS/src/Core/OutputProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,6 +33,8 @@ public OutputProducer(Pipe pipe)
}

public PipeReader Reader => _pipe.Reader;

public bool Aborted => _aborted;

public Task FlushAsync(CancellationToken cancellationToken)
{
Expand All @@ -44,7 +47,7 @@ public void Complete()
{
lock (_contextLock)
{
if (_completed)
if (_completed || _aborted)
{
return;
}
Expand All @@ -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();
Expand All @@ -74,7 +77,7 @@ public Task WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellati
{
lock (_contextLock)
{
if (_completed)
if (_completed || _aborted)
{
return Task.CompletedTask;
}
Expand Down
1 change: 0 additions & 1 deletion src/Servers/IIS/IIS/test/IIS.Tests/ResponseAbortTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public async Task ClosesWithoutSendingAnything()
}

[ConditionalFact]
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/31404")]
public async Task ClosesAfterDataSent()
{
var bodyReceived = CreateTaskCompletionSource();
Expand Down