diff --git a/src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs b/src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs index 8f6341db63ce..ba14d5ca7cf9 100644 --- a/src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs +++ b/src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs @@ -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."); + } _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; } @@ -666,8 +669,8 @@ protected override unsafe void Dispose(bool disposing) { return; } - _disposed = true; FlushInternal(endOfRequest: true); + _disposed = true; } } finally