33
44using System ;
55using System . Buffers ;
6- using System . Diagnostics ;
76using System . IO . Pipelines ;
87using System . Threading ;
98using System . Threading . Tasks ;
1211using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
1312using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http2 . FlowControl ;
1413using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
14+ using Microsoft . Extensions . Logging ;
1515
1616namespace 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