Skip to content

Commit 146cf0a

Browse files
committed
comment + rename
1 parent b076b7d commit 146cf0a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ private void WriteResponseHeadersUnsynchronized(int streamId, int statusCode, Ht
502502
_outgoingFrame.PrepareHeaders(headerFrameFlags, streamId);
503503
var buffer = _headerEncodingBuffer.AsSpan();
504504
var done = HPackHeaderWriter.BeginEncodeHeaders(statusCode, _hpackEncoder, _headersEnumerator, buffer, out var payloadLength);
505-
FinishWritingHeaders(streamId, payloadLength, done);
505+
FinishWritingHeadersUnsynchronized(streamId, payloadLength, done);
506506
}
507507
// Any exception from the HPack encoder can leave the dynamic table in a corrupt state.
508508
// Since we allow custom header encoders we don't know what type of exceptions to expect.
@@ -543,7 +543,7 @@ private ValueTask<FlushResult> WriteDataAndTrailersAsync(Http2Stream stream, in
543543
_outgoingFrame.PrepareHeaders(Http2HeadersFrameFlags.END_STREAM, streamId);
544544
var buffer = _headerEncodingBuffer.AsSpan();
545545
var done = HPackHeaderWriter.BeginEncodeHeaders(_hpackEncoder, _headersEnumerator, buffer, out var payloadLength);
546-
FinishWritingHeaders(streamId, payloadLength, done);
546+
FinishWritingHeadersUnsynchronized(streamId, payloadLength, done);
547547
}
548548
// Any exception from the HPack encoder can leave the dynamic table in a corrupt state.
549549
// Since we allow custom header encoders we don't know what type of exceptions to expect.
@@ -557,7 +557,7 @@ private ValueTask<FlushResult> WriteDataAndTrailersAsync(Http2Stream stream, in
557557
}
558558
}
559559

560-
private void FinishWritingHeaders(int streamId, int payloadLength, bool done)
560+
private void FinishWritingHeadersUnsynchronized(int streamId, int payloadLength, bool done)
561561
{
562562
var buffer = _headerEncodingBuffer.AsSpan();
563563
_outgoingFrame.PayloadLength = payloadLength;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ internal void OnRequestProcessingEnded()
605605
}
606606

607607
// Complete outside of lock, anything this method does that needs a lock will acquire a lock itself.
608+
// Additionally, this method should only be called once per Reset so calling outside of the lock is fine from the perspective
609+
// of multiple threads calling OnRequestProcessingEnded.
608610
if (shouldCompleteStream)
609611
{
610612
Stream.CompleteStream(errored: false);
@@ -638,6 +640,8 @@ internal ValueTask<FlushResult> CompleteResponseAsync()
638640
}
639641

640642
// Complete outside of lock, anything this method does that needs a lock will acquire a lock itself.
643+
// CompleteResponseAsync also should never be called in parallel so calling this outside of the lock doesn't
644+
// cause any weirdness with parallel threads calling this method and no longer waiting on the stream completion call.
641645
if (shouldCompleteStream)
642646
{
643647
Stream.CompleteStream(errored: false);

0 commit comments

Comments
 (0)