3
3
4
4
using System ;
5
5
using System . Buffers ;
6
- using System . Diagnostics ;
7
6
using System . IO . Pipelines ;
8
7
using System . Threading ;
9
8
using System . Threading . Tasks ;
12
11
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
13
12
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http2 . FlowControl ;
14
13
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
14
+ using Microsoft . Extensions . Logging ;
15
15
16
16
namespace Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http2
17
17
{
@@ -20,6 +20,7 @@ internal class Http2OutputProducer : IHttpOutputProducer, IHttpOutputAborter
20
20
private readonly int _streamId ;
21
21
private readonly Http2FrameWriter _frameWriter ;
22
22
private readonly TimingPipeFlusher _flusher ;
23
+ private readonly IKestrelTrace _log ;
23
24
24
25
// This should only be accessed via the FrameWriter. The connection-level output flow control is protected by the
25
26
// FrameWriter's connection-level write lock.
@@ -46,6 +47,8 @@ public Http2OutputProducer(
46
47
_frameWriter = frameWriter ;
47
48
_flowControl = flowControl ;
48
49
_stream = stream ;
50
+ _log = log ;
51
+
49
52
_dataPipe = CreateDataPipe ( pool ) ;
50
53
_flusher = new TimingPipeFlusher ( _dataPipe . Writer , timeoutControl , log ) ;
51
54
_dataWriteProcessingTask = ProcessDataWrites ( ) ;
@@ -327,7 +330,10 @@ private async ValueTask<FlushResult> ProcessDataWrites()
327
330
}
328
331
else if ( readResult . IsCompleted && _streamEnded )
329
332
{
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
+ }
331
337
332
338
// Headers have already been written and there is no other content to write
333
339
flushResult = await _frameWriter . FlushAsync ( outputAborter : null , cancellationToken : default ) ;
@@ -346,7 +352,7 @@ private async ValueTask<FlushResult> ProcessDataWrites()
346
352
}
347
353
catch ( Exception ex )
348
354
{
349
- Debug . Assert ( false , ex . ToString ( ) ) ;
355
+ _log . LogCritical ( ex , "Http2OutpuProducer.ProcessDataWrites() observed an unexpected exception." ) ;
350
356
}
351
357
352
358
_dataPipe . Reader . Complete ( ) ;
0 commit comments