Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ public async Task SendRequestBodyAsync(CancellationToken cancellationToken)
sendReset = _responseCompletionState == StreamCompletionState.Failed;
Complete();
}
}

if (sendReset)
{
SendReset();
}
else
{
// Send EndStream asynchronously and without cancellation.
// If this fails, it means that the connection is aborting and we will be reset.
_connection.LogExceptions(_connection.SendEndStreamAsync(StreamId));
if (sendReset)
{
SendReset();
}
else
{
// Send EndStream asynchronously and without cancellation.
// If this fails, it means that the connection is aborting and we will be reset.
_connection.LogExceptions(_connection.SendEndStreamAsync(StreamId));
}
}
}
}
Expand Down Expand Up @@ -325,7 +325,6 @@ public async ValueTask<bool> WaitFor100ContinueAsync(CancellationToken cancellat

private void SendReset()
{
Debug.Assert(!Monitor.IsEntered(SyncObject));
Debug.Assert(_requestCompletionState != StreamCompletionState.InProgress);
Debug.Assert(_responseCompletionState != StreamCompletionState.InProgress);
Debug.Assert(_requestCompletionState == StreamCompletionState.Failed || _responseCompletionState == StreamCompletionState.Failed,
Expand All @@ -336,7 +335,13 @@ private void SendReset()
// Don't send a RST_STREAM if we've already received one from the server.
if (_resetException == null)
{
_connection.LogExceptions(_connection.SendRstStreamAsync(StreamId, Http2ProtocolErrorCode.Cancel));
// Use dedicated lock to prevent sending a frame with EndStream flag after an RST_STREAM frame.
// If execution reached this line, it's guaranteed that
// _requestCompletionState == StreamCompletionState.Failed or _responseCompletionState == StreamCompletionState.Failed
lock (SyncObject)
{
_connection.LogExceptions(_connection.SendRstStreamAsync(StreamId, Http2ProtocolErrorCode.Cancel));
}
}
}

Expand Down