@@ -58,9 +58,7 @@ internal class Http1OutputProducer : IHttpOutputProducer, IDisposable
58
58
59
59
private bool _autoChunk ;
60
60
61
- // We rely on the TimingPipeFlusher to give us ValueTasks that can be safely awaited multiple times.
62
61
private bool _writeStreamSuffixCalled ;
63
- private ValueTask < FlushResult > _writeStreamSuffixValueTask ;
64
62
65
63
private int _advancedBytesForChunk ;
66
64
private Memory < byte > _currentChunkMemory ;
@@ -118,31 +116,27 @@ public ValueTask<FlushResult> WriteDataToPipeAsync(ReadOnlySpan<byte> buffer, Ca
118
116
119
117
public ValueTask < FlushResult > WriteStreamSuffixAsync ( )
120
118
{
119
+ ValueTask < FlushResult > result = default ;
120
+
121
121
lock ( _contextLock )
122
122
{
123
- if ( _writeStreamSuffixCalled )
123
+ if ( ! _writeStreamSuffixCalled )
124
124
{
125
- // If WriteStreamSuffixAsync has already been called, no-op and return the previously returned ValueTask.
126
- return _writeStreamSuffixValueTask ;
127
- }
125
+ if ( _autoChunk )
126
+ {
127
+ var writer = new BufferWriter < PipeWriter > ( _pipeWriter ) ;
128
+ result = WriteAsyncInternal ( ref writer , EndChunkedResponseBytes ) ;
129
+ }
130
+ else if ( _unflushedBytes > 0 )
131
+ {
132
+ result = FlushAsync ( ) ;
133
+ }
128
134
129
- if ( _autoChunk )
130
- {
131
- var writer = new BufferWriter < PipeWriter > ( _pipeWriter ) ;
132
- _writeStreamSuffixValueTask = WriteAsyncInternal ( ref writer , EndChunkedResponseBytes ) ;
133
- }
134
- else if ( _unflushedBytes > 0 )
135
- {
136
- _writeStreamSuffixValueTask = FlushAsync ( ) ;
137
- }
138
- else
139
- {
140
- _writeStreamSuffixValueTask = default ;
135
+ _writeStreamSuffixCalled = true ;
141
136
}
142
-
143
- _writeStreamSuffixCalled = true ;
144
- return _writeStreamSuffixValueTask ;
145
137
}
138
+
139
+ return result ;
146
140
}
147
141
148
142
public ValueTask < FlushResult > FlushAsync ( CancellationToken cancellationToken = default )
@@ -533,7 +527,6 @@ public void Reset()
533
527
_currentMemoryPrefixBytes = 0 ;
534
528
_autoChunk = false ;
535
529
_writeStreamSuffixCalled = false ;
536
- _writeStreamSuffixValueTask = default ;
537
530
_currentChunkMemoryUpdated = false ;
538
531
_startCalled = false ;
539
532
}
0 commit comments