Skip to content

Commit

Permalink
comment + rename
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy committed Apr 11, 2024
1 parent b076b7d commit 146cf0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private void WriteResponseHeadersUnsynchronized(int streamId, int statusCode, Ht
_outgoingFrame.PrepareHeaders(headerFrameFlags, streamId);
var buffer = _headerEncodingBuffer.AsSpan();
var done = HPackHeaderWriter.BeginEncodeHeaders(statusCode, _hpackEncoder, _headersEnumerator, buffer, out var payloadLength);
FinishWritingHeaders(streamId, payloadLength, done);
FinishWritingHeadersUnsynchronized(streamId, payloadLength, done);
}
// Any exception from the HPack encoder can leave the dynamic table in a corrupt state.
// Since we allow custom header encoders we don't know what type of exceptions to expect.
Expand Down Expand Up @@ -543,7 +543,7 @@ private ValueTask<FlushResult> WriteDataAndTrailersAsync(Http2Stream stream, in
_outgoingFrame.PrepareHeaders(Http2HeadersFrameFlags.END_STREAM, streamId);
var buffer = _headerEncodingBuffer.AsSpan();
var done = HPackHeaderWriter.BeginEncodeHeaders(_hpackEncoder, _headersEnumerator, buffer, out var payloadLength);
FinishWritingHeaders(streamId, payloadLength, done);
FinishWritingHeadersUnsynchronized(streamId, payloadLength, done);
}
// Any exception from the HPack encoder can leave the dynamic table in a corrupt state.
// Since we allow custom header encoders we don't know what type of exceptions to expect.
Expand All @@ -557,7 +557,7 @@ private ValueTask<FlushResult> WriteDataAndTrailersAsync(Http2Stream stream, in
}
}

private void FinishWritingHeaders(int streamId, int payloadLength, bool done)
private void FinishWritingHeadersUnsynchronized(int streamId, int payloadLength, bool done)
{
var buffer = _headerEncodingBuffer.AsSpan();
_outgoingFrame.PayloadLength = payloadLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ internal void OnRequestProcessingEnded()
}

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

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

0 comments on commit 146cf0a

Please sign in to comment.