7
7
using System . Net . Http ;
8
8
using System . Threading . Tasks ;
9
9
using Microsoft . AspNetCore . Connections ;
10
+ using Microsoft . AspNetCore . Http ;
10
11
using Microsoft . AspNetCore . Server . Kestrel . Core . Features ;
11
12
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http3 ;
12
13
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
@@ -263,6 +264,29 @@ public async Task ResponseDrain_SlowerThanMinimumDataRate_AbortsConnection()
263
264
}
264
265
*/
265
266
267
+ private class EchoAppWithNotification
268
+ {
269
+ private readonly TaskCompletionSource _writeStartedTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
270
+
271
+ public Task WriteStartedTask => _writeStartedTcs . Task ;
272
+
273
+ public async Task RunApp ( HttpContext context )
274
+ {
275
+ await context . Response . Body . FlushAsync ( ) ;
276
+
277
+ var buffer = new byte [ 16 * 1024 ] ;
278
+ int received ;
279
+
280
+ while ( ( received = await context . Request . Body . ReadAsync ( buffer , 0 , buffer . Length ) ) > 0 )
281
+ {
282
+ var writeTask = context . Response . Body . WriteAsync ( buffer , 0 , received ) ;
283
+ _writeStartedTcs . TrySetResult ( ) ;
284
+
285
+ await writeTask ;
286
+ }
287
+ }
288
+ }
289
+
266
290
[ Fact ]
267
291
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/21520" ) ]
268
292
public async Task DATA_Sent_TooSlowlyDueToSocketBackPressureOnSmallWrite_AbortsConnectionAfterGracePeriod ( )
@@ -278,13 +302,16 @@ public async Task DATA_Sent_TooSlowlyDueToSocketBackPressureOnSmallWrite_AbortsC
278
302
279
303
_timeoutControl . Initialize ( mockSystemClock . UtcNow . Ticks ) ;
280
304
281
- var requestStream = await InitializeConnectionAndStreamsAsync ( _echoApplication ) ;
305
+ var app = new EchoAppWithNotification ( ) ;
306
+ var requestStream = await InitializeConnectionAndStreamsAsync ( app . RunApp ) ;
282
307
283
308
await requestStream . SendHeadersAsync ( _browserRequestHeaders , endStream : false ) ;
284
309
await requestStream . SendDataAsync ( _helloWorldBytes , endStream : true ) ;
285
310
286
311
await requestStream . ExpectHeadersAsync ( ) ;
287
312
313
+ await app . WriteStartedTask . DefaultTimeout ( ) ;
314
+
288
315
// Complete timing of the request body so we don't induce any unexpected request body rate timeouts.
289
316
_timeoutControl . Tick ( mockSystemClock . UtcNow ) ;
290
317
@@ -306,7 +333,6 @@ public async Task DATA_Sent_TooSlowlyDueToSocketBackPressureOnSmallWrite_AbortsC
306
333
}
307
334
308
335
[ Fact ]
309
- [ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/21520" ) ]
310
336
public async Task DATA_Sent_TooSlowlyDueToSocketBackPressureOnLargeWrite_AbortsConnectionAfterRateTimeout ( )
311
337
{
312
338
var mockSystemClock = _serviceContext . MockSystemClock ;
@@ -320,18 +346,21 @@ public async Task DATA_Sent_TooSlowlyDueToSocketBackPressureOnLargeWrite_AbortsC
320
346
321
347
_timeoutControl . Initialize ( mockSystemClock . UtcNow . Ticks ) ;
322
348
323
- var requestStream = await InitializeConnectionAndStreamsAsync ( _echoApplication ) ;
349
+ var app = new EchoAppWithNotification ( ) ;
350
+ var requestStream = await InitializeConnectionAndStreamsAsync ( app . RunApp ) ;
324
351
325
352
await requestStream . SendHeadersAsync ( _browserRequestHeaders , endStream : false ) ;
326
353
await requestStream . SendDataAsync ( _maxData , endStream : true ) ;
327
354
328
355
await requestStream . ExpectHeadersAsync ( ) ;
329
356
357
+ await app . WriteStartedTask . DefaultTimeout ( ) ;
358
+
330
359
// Complete timing of the request body so we don't induce any unexpected request body rate timeouts.
331
360
_timeoutControl . Tick ( mockSystemClock . UtcNow ) ;
332
361
333
362
var timeToWriteMaxData = TimeSpan . FromSeconds ( ( requestStream . BytesReceived + _maxData . Length ) / limits . MinResponseDataRate . BytesPerSecond ) +
334
- Heartbeat . Interval - TimeSpan . FromSeconds ( .5 ) ;
363
+ limits . MinResponseDataRate . GracePeriod + Heartbeat . Interval - TimeSpan . FromSeconds ( .5 ) ;
335
364
336
365
// Don't read data frame to induce "socket" backpressure.
337
366
AdvanceClock ( timeToWriteMaxData ) ;
0 commit comments