Skip to content

Commit 10d70c5

Browse files
authored
Fix AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires (#9487)
1 parent caac31c commit 10d70c5

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,13 @@ internal void VerifyGoAway(Http2Frame frame, int expectedLastStreamId, Http2Erro
11631163

11641164
internal async Task WaitForConnectionErrorAsync<TException>(bool ignoreNonGoAwayFrames, int expectedLastStreamId, Http2ErrorCode expectedErrorCode, params string[] expectedErrorMessage)
11651165
where TException : Exception
1166+
{
1167+
await WaitForConnectionErrorAsyncDoNotCloseTransport<TException>(ignoreNonGoAwayFrames, expectedLastStreamId, expectedErrorCode, expectedErrorMessage);
1168+
_pair.Application.Output.Complete();
1169+
}
1170+
1171+
internal async Task WaitForConnectionErrorAsyncDoNotCloseTransport<TException>(bool ignoreNonGoAwayFrames, int expectedLastStreamId, Http2ErrorCode expectedErrorCode, params string[] expectedErrorMessage)
1172+
where TException : Exception
11661173
{
11671174
var frame = await ReceiveFrameAsync();
11681175

@@ -1184,7 +1191,7 @@ internal async Task WaitForConnectionErrorAsync<TException>(bool ignoreNonGoAway
11841191
}
11851192

11861193
await _connectionTask.DefaultTimeout();
1187-
_pair.Application.Output.Complete();
1194+
TestApplicationErrorLogger.LogInformation("Stopping Connection From ConnectionErrorAsync");
11881195
}
11891196

11901197
internal async Task WaitForStreamErrorAsync(int expectedStreamId, Http2ErrorCode expectedErrorCode, string expectedErrorMessage)

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TimeoutTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
1212
using Microsoft.AspNetCore.Testing;
1313
using Microsoft.AspNetCore.Testing.xunit;
14+
using Microsoft.Extensions.Logging.Testing;
1415
using Microsoft.Net.Http.Headers;
1516
using Moq;
1617
using Xunit;
@@ -193,11 +194,13 @@ public async Task ResponseDrain_SlowerThanMinimumDataRate_AbortsConnection()
193194
}
194195

195196
[Theory]
196-
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/1879", FlakyOn.All)]
197+
[Repeat(20)]
197198
[InlineData((int)Http2FrameType.DATA)]
198199
[InlineData((int)Http2FrameType.CONTINUATION)]
199200
public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires(int intFinalFrameType)
200201
{
202+
var closeLock = new object();
203+
var closed = false;
201204
var finalFrameType = (Http2FrameType)intFinalFrameType;
202205
// Remove callback that completes _pair.Application.Output on abort.
203206
_mockConnectionContext.Reset();
@@ -216,8 +219,6 @@ public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldow
216219

217220
await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, "The connection was aborted by the application.");
218221

219-
var cts = new CancellationTokenSource();
220-
221222
async Task AdvanceClockAndSendFrames()
222223
{
223224
if (finalFrameType == Http2FrameType.CONTINUATION)
@@ -227,7 +228,7 @@ async Task AdvanceClockAndSendFrames()
227228
}
228229

229230
// There's a race when the appfunc is exiting about how soon it unregisters the stream, so retry until success.
230-
while (!cts.Token.IsCancellationRequested)
231+
while (!closed)
231232
{
232233
// Just past the timeout
233234
mockSystemClock.UtcNow += Constants.RequestBodyDrainTimeout + TimeSpan.FromTicks(1);
@@ -247,24 +248,24 @@ async Task AdvanceClockAndSendFrames()
247248
throw new NotImplementedException(finalFrameType.ToString());
248249
}
249250

250-
if (!cts.Token.IsCancellationRequested)
251-
{
252-
await Task.Delay(10);
253-
}
251+
// TODO how do I force a function to go async?
252+
await Task.Delay(1);
254253
}
255254
}
256255

257256
var sendTask = AdvanceClockAndSendFrames();
258257

259-
await WaitForConnectionErrorAsync<Http2ConnectionErrorException>(
258+
await WaitForConnectionErrorAsyncDoNotCloseTransport<Http2ConnectionErrorException>(
260259
ignoreNonGoAwayFrames: false,
261260
expectedLastStreamId: 1,
262261
Http2ErrorCode.STREAM_CLOSED,
263262
CoreStrings.FormatHttp2ErrorStreamClosed(finalFrameType, 1));
264263

265-
cts.Cancel();
264+
closed = true;
266265

267266
await sendTask.DefaultTimeout();
267+
268+
_pair.Application.Output.Complete();
268269
}
269270

270271
[Fact]

0 commit comments

Comments
 (0)