Skip to content

Suppress log when request is cancelled #16691

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

Merged
merged 3 commits into from
Nov 20, 2019
Merged
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
9 changes: 6 additions & 3 deletions src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ public override void Flush()
var flags = ComputeLeftToWrite(data.Count, endOfRequest);
if (endOfRequest && _leftToWrite > 0)
{
if (!RequestContext.DisconnectToken.IsCancellationRequested)
{
// This is logged rather than thrown because it is too late for an exception to be visible in user code.
LogHelper.LogError(Logger, "ResponseStream::Dispose", "Fewer bytes were written than were specified in the Content-Length.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kahbazi can you write a unit test to verify this behavior? Or is there a race and it makes it hard to write a test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to try some manual verification before merging this. I don't know if DisconnectToken.IsCancellationRequested is consistent enough in these scenarios for this to work as expected.

}
_requestContext.Abort();
// This is logged rather than thrown because it is too late for an exception to be visible in user code.
LogHelper.LogError(Logger, "ResponseStream::Dispose", "Fewer bytes were written than were specified in the Content-Length.");
return;
}

Expand Down Expand Up @@ -666,8 +669,8 @@ protected override unsafe void Dispose(bool disposing)
{
return;
}
_disposed = true;
FlushInternal(endOfRequest: true);
_disposed = true;
}
}
finally
Expand Down