Skip to content

Remove Debug.Assert from Http2OutputProducer #11624

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 1 commit into from
Jun 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Buffers;
using System.Diagnostics;
using System.IO.Pipelines;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -12,6 +11,7 @@
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{
Expand All @@ -20,6 +20,7 @@ internal class Http2OutputProducer : IHttpOutputProducer, IHttpOutputAborter
private readonly int _streamId;
private readonly Http2FrameWriter _frameWriter;
private readonly TimingPipeFlusher _flusher;
private readonly IKestrelTrace _log;

// This should only be accessed via the FrameWriter. The connection-level output flow control is protected by the
// FrameWriter's connection-level write lock.
Expand All @@ -46,6 +47,8 @@ public Http2OutputProducer(
_frameWriter = frameWriter;
_flowControl = flowControl;
_stream = stream;
_log = log;

_dataPipe = CreateDataPipe(pool);
_flusher = new TimingPipeFlusher(_dataPipe.Writer, timeoutControl, log);
_dataWriteProcessingTask = ProcessDataWrites();
Expand Down Expand Up @@ -327,7 +330,10 @@ private async ValueTask<FlushResult> ProcessDataWrites()
}
else if (readResult.IsCompleted && _streamEnded)
{
Debug.Assert(readResult.Buffer.Length == 0);
Copy link
Member Author

Choose a reason for hiding this comment

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

This assertion never failed as far as I'm aware, but that was the only other Debug.Assert in the class, so I changed it so it also just results in a critical log if it fails.

if (readResult.Buffer.Length != 0)
{
throw new Exception("Http2OutpuProducer.ProcessDataWrites() observed an unexpected state where the streams output ended with data still remaining in the pipe.");
}

// Headers have already been written and there is no other content to write
flushResult = await _frameWriter.FlushAsync(outputAborter: null, cancellationToken: default);
Expand All @@ -346,7 +352,7 @@ private async ValueTask<FlushResult> ProcessDataWrites()
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
_log.LogCritical(ex, "Http2OutpuProducer.ProcessDataWrites() observed an unexpected exception.");
}

_dataPipe.Reader.Complete();
Expand Down