Skip to content
Merged
Changes from all 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 @@ -245,9 +245,10 @@ public async Task SendRequestBodyAsync(CancellationToken cancellationToken)

_requestCompletionState = StreamCompletionState.Failed;
Complete();

SendReset();
}

SendReset();
if (signalWaiter)
{
_waitSource.SetResult(true);
Expand Down Expand Up @@ -275,17 +276,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 +326,7 @@ public async ValueTask<bool> WaitFor100ContinueAsync(CancellationToken cancellat

private void SendReset()
{
Debug.Assert(!Monitor.IsEntered(SyncObject));
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,6 +337,8 @@ private void SendReset()
// Don't send a RST_STREAM if we've already received one from the server.
if (_resetException == null)
{
// If execution reached this line, it's guaranteed that
// _requestCompletionState == StreamCompletionState.Failed or _responseCompletionState == StreamCompletionState.Failed
_connection.LogExceptions(_connection.SendRstStreamAsync(StreamId, Http2ProtocolErrorCode.Cancel));
}
}
Expand Down Expand Up @@ -384,9 +387,12 @@ private void Cancel()
// When cancellation propagates, SendRequestBodyAsync will set _requestCompletionState to Failed
requestBodyCancellationSource?.Cancel();

if (sendReset)
lock (SyncObject)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really happy to lock on the same object just after leaving the above lock block, but it seems dangerous to change order of requestBodyCancellationSource?.Cancel() and SendReset calls as well as to move requestBodyCancellationSource?.Cancel() under the above lock.

{
SendReset();
if (sendReset)
{
SendReset();
}
}

if (signalWaiter)
Expand Down