Skip to content

Commit

Permalink
Complete Http2Stream after sending Reset or EndOfStream to server (#5…
Browse files Browse the repository at this point in the history
…5835)

It changes the order of Complete and Send Reset/Send EndOfStream operations to prevent creation of a new Http2Stream while the old one has not yet written the final frame to wire.

Fixes #1586
  • Loading branch information
alnikola authored Jul 20, 2021
1 parent 0e5e88c commit ef2fe6e
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ public async Task SendRequestBodyAsync(CancellationToken cancellationToken)
Debug.Assert(!sendReset);

_requestCompletionState = StreamCompletionState.Failed;
Complete();

SendReset();
Complete();
}

if (signalWaiter)
Expand All @@ -270,11 +269,12 @@ public async Task SendRequestBodyAsync(CancellationToken cancellationToken)
Debug.Assert(_requestCompletionState == StreamCompletionState.InProgress, $"Request already completed with state={_requestCompletionState}");
_requestCompletionState = StreamCompletionState.Completed;

bool complete = false;
if (_responseCompletionState != StreamCompletionState.InProgress)
{
// Note, we can reach this point if the response stream failed but cancellation didn't propagate before we finished.
sendReset = _responseCompletionState == StreamCompletionState.Failed;
Complete();
complete = true;
}

if (sendReset)
Expand All @@ -287,6 +287,11 @@ public async Task SendRequestBodyAsync(CancellationToken cancellationToken)
// If this fails, it means that the connection is aborting and we will be reset.
_connection.LogExceptions(_connection.SendEndStreamAsync(StreamId));
}

if (complete)
{
Complete();
}
}
}
}
Expand Down Expand Up @@ -392,6 +397,7 @@ private void Cancel()
if (sendReset)
{
SendReset();
Complete();
}
}

Expand All @@ -414,7 +420,6 @@ private void Cancel()
if (_requestCompletionState != StreamCompletionState.InProgress)
{
sendReset = true;
Complete();
}
}

Expand Down

0 comments on commit ef2fe6e

Please sign in to comment.