Skip to content

Commit 11ff4bd

Browse files
committed
Remove Debug.Assert from Http2OutputProducer
1 parent 785cd9a commit 11ff4bd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Buffers;
6-
using System.Diagnostics;
76
using System.IO.Pipelines;
87
using System.Threading;
98
using System.Threading.Tasks;
@@ -12,6 +11,7 @@
1211
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
1312
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
1413
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
14+
using Microsoft.Extensions.Logging;
1515

1616
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
1717
{
@@ -20,6 +20,7 @@ internal class Http2OutputProducer : IHttpOutputProducer, IHttpOutputAborter
2020
private readonly int _streamId;
2121
private readonly Http2FrameWriter _frameWriter;
2222
private readonly TimingPipeFlusher _flusher;
23+
private readonly IKestrelTrace _log;
2324

2425
// This should only be accessed via the FrameWriter. The connection-level output flow control is protected by the
2526
// FrameWriter's connection-level write lock.
@@ -46,6 +47,8 @@ public Http2OutputProducer(
4647
_frameWriter = frameWriter;
4748
_flowControl = flowControl;
4849
_stream = stream;
50+
_log = log;
51+
4952
_dataPipe = CreateDataPipe(pool);
5053
_flusher = new TimingPipeFlusher(_dataPipe.Writer, timeoutControl, log);
5154
_dataWriteProcessingTask = ProcessDataWrites();
@@ -327,7 +330,10 @@ private async ValueTask<FlushResult> ProcessDataWrites()
327330
}
328331
else if (readResult.IsCompleted && _streamEnded)
329332
{
330-
Debug.Assert(readResult.Buffer.Length == 0);
333+
if (readResult.Buffer.Length != 0)
334+
{
335+
throw new Exception("Http2OutpuProducer.ProcessDataWrites() observed an unexpected state where the streams output ended with data still remaining in the pipe.");
336+
}
331337

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

352358
_dataPipe.Reader.Complete();

0 commit comments

Comments
 (0)