Skip to content
Closed
Changes from 2 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 @@ -608,6 +608,10 @@ static async Task RunTest(string useVersion, string testAsync, string useTlsStri
VerifyParent = false
};

// Synchronize client and server: server waits for client to finish req1 assertions before reading req2.
// This prevents a race where the server tries to read req2 before the client sends it.
TaskCompletionSource req1AssertionsDone = new(TaskCreationOptions.RunContinuationsAsynchronously);

await GetFactoryForVersion(useVersion).CreateClientAndServerAsync(
async uri =>
{
Expand Down Expand Up @@ -694,6 +698,9 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync(
ActivityAssert.HasTag(conn, "server.port", uri.Port);
ActivityAssert.HasTag(conn, "url.scheme", useTls ? "https" : "http");

// Signal the server to read the second request now that all req1 assertions have passed.
req1AssertionsDone.SetResult();

// The second request should reuse the first connection, connection_setup and wait_for_connection should not be recorded again.
await client.SendAsync(CreateRequest(HttpMethod.Get, uri, Version.Parse(useVersion), exactVersion: true));
requestRecorder.VerifyActivityRecorded(2);
Expand All @@ -713,6 +720,11 @@ await server.AcceptConnectionAsync(async connection =>
await connection.SendResponseAsync(HttpStatusCode.OK);
connection.CompleteRequestProcessing();

// Wait for the client to finish asserting the first request before reading the second.
// This prevents a race where a client assertion failure closes the connection before
// the second request is sent, causing a spurious server-side EOF exception.
await req1AssertionsDone.Task;

await connection.ReadRequestDataAsync();
await connection.SendResponseAsync(HttpStatusCode.OK);
});
Expand Down