Skip to content

Commit

Permalink
Flaky multiple HTTP/2 connection tests read full request body (dotnet…
Browse files Browse the repository at this point in the history
…#40844)

There are 2 flaky HTTP/2 tests verifying multiple connections feature which are randomly failing on CI, but not locally.
- Http2_MultipleConnectionsEnabled_ConnectionLimitNotReached_ConcurrentRequestsSuccessfullyHandled
- Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_ConnectionRemovedAndNewCreated

It seems the failure is caused by not reading the request body. In current implementation, `Http2LoopbackServer` read only HEADERS frame via `ReadRequestHeaderAsync` and then immediately sends response. However, the client firstly completely sends headers and body and only then starting reading a response. Thus, it seems to get blocked sometimes if the server didn't read the full body. This PR fixes this by calling `ReadAndParseRequestHeaderAsync` instead of `ReadRequestHeaderAsync`.

Fixes dotnet#40436
Fixes dotnet#40115
  • Loading branch information
alnikola committed Aug 14, 2020
1 parent 46a563a commit 056f728
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2303,23 +2303,24 @@ private static async Task<Http2LoopbackConnection> GetConnection(Http2LoopbackSe

private async Task<(int Count, int LastStreamId)> HandleAllPendingRequests(Http2LoopbackConnection connection, int totalRequestCount)
{
int streamId = -1;
int lastStreamId = -1;
for (int i = 0; i < totalRequestCount; i++)
{
try
{
// Exact number of requests sent over the given connection is unknown,
// so we keep reading headers and sending response while there are available requests.
streamId = await connection.ReadRequestHeaderAsync().ConfigureAwait(false);
(int streamId, _) = await connection.ReadAndParseRequestHeaderAsync().ConfigureAwait(false);
await connection.SendDefaultResponseAsync(streamId).ConfigureAwait(false);
lastStreamId = streamId;
}
catch (OperationCanceledException)
{
return (i, streamId);
return (i, lastStreamId);
}
}

return (totalRequestCount, streamId);
return (totalRequestCount, lastStreamId);
}

private async Task<List<int>> AcceptRequests(Http2LoopbackConnection connection, int maxRequests = int.MaxValue)
Expand All @@ -2329,7 +2330,8 @@ private async Task<List<int>> AcceptRequests(Http2LoopbackConnection connection,
{
try
{
streamIds.Add(await connection.ReadRequestHeaderAsync().ConfigureAwait(false));
(int streamId, _) = await connection.ReadAndParseRequestHeaderAsync().ConfigureAwait(false);
streamIds.Add(streamId);
}
catch (OperationCanceledException)
{
Expand Down

0 comments on commit 056f728

Please sign in to comment.