diff --git a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs index c41212972d..96083d7ae8 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs @@ -1274,7 +1274,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - await Assert.ThrowsAsync(async () => await readTcs.Task); + var thrownEx = await Assert.ThrowsAnyAsync(async () => await readTcs.Task); + + // https://github.com/aspnet/AspNetCore-Internal/issues/1521 + // In more recent versions of Kestrel, we expect this to always be a TaskCanceledException, + // but without the changes in https://github.com/aspnet/KestrelHttpServer/pull/2844, this is flaky. + Assert.True(thrownEx is TaskCanceledException || thrownEx is IOException, $"{thrownEx} is neither a TaskCanceledException nor IOException."); // The cancellation token for only the last request should be triggered. var abortedRequestId = await registrationTcs.Task;