Skip to content

Commit 5a0e227

Browse files
authored
Merge branch 'release/2.2'
2 parents 91f9c63 + 522705f commit 5a0e227

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

eng/PatchConfig.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Later on, this will be checked using this condition:
2626
Microsoft.AspNetCore.Mvc.Core;
2727
Microsoft.AspNetCore.Routing;
2828
Microsoft.AspNetCore.Server.IIS;
29-
Microsoft.AspNetCore.Server.Kestrel.Core;
3029
java:signalr;
3130
</PackagesInPatch>
3231
</PropertyGroup>

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,11 @@ public void Reset()
367367
// Lock to prevent CancelRequestAbortedToken from attempting to cancel an disposed CTS.
368368
lock (_abortLock)
369369
{
370-
_abortedCts?.Dispose();
371-
_abortedCts = null;
370+
if (!_requestAborted)
371+
{
372+
_abortedCts?.Dispose();
373+
_abortedCts = null;
374+
}
372375
}
373376

374377
_requestHeadersParsed = 0;
@@ -412,16 +415,15 @@ protected virtual bool BeginRead(out ValueTask<ReadResult> awaitable)
412415

413416
private void CancelRequestAbortedToken()
414417
{
415-
lock (_abortLock)
418+
try
416419
{
417-
try
418-
{
419-
_abortedCts?.Cancel();
420-
}
421-
catch (Exception ex)
422-
{
423-
Log.ApplicationError(ConnectionId, TraceIdentifier, ex);
424-
}
420+
_abortedCts.Cancel();
421+
_abortedCts.Dispose();
422+
_abortedCts = null;
423+
}
424+
catch (Exception ex)
425+
{
426+
Log.ApplicationError(ConnectionId, TraceIdentifier, ex);
425427
}
426428
}
427429

@@ -435,12 +437,12 @@ protected void AbortRequest()
435437
}
436438

437439
_requestAborted = true;
440+
}
438441

439-
if (_abortedCts != null && !_preventRequestAbortedCancellation)
440-
{
441-
// Potentially calling user code. CancelRequestAbortedToken logs any exceptions.
442-
ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this);
443-
}
442+
if (_abortedCts != null)
443+
{
444+
// Potentially calling user code. CancelRequestAbortedToken logs any exceptions.
445+
ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this);
444446
}
445447
}
446448

@@ -460,6 +462,8 @@ private void PreventRequestAbortedCancellation()
460462
}
461463

462464
_preventRequestAbortedCancellation = true;
465+
_abortedCts?.Dispose();
466+
_abortedCts = null;
463467
}
464468
}
465469

src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,16 @@ public async Task RequestAbortedTokenIsResetBeforeLastWriteWithChunkedEncoding()
729729
}
730730

731731
[Fact]
732-
public void RequestAbortedTokenIsFullyUsableAfterCancellation()
732+
public void RequestAbortedTokenIsUsableAfterCancellation()
733733
{
734734
var originalToken = _http1Connection.RequestAborted;
735735
var originalRegistration = originalToken.Register(() => { });
736736

737737
_http1Connection.Abort(new ConnectionAbortedException());
738738

739-
Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
739+
// The following line will throw an ODE because the original CTS backing the token has been diposed.
740+
// See https://github.com/aspnet/AspNetCore/pull/4447 for the history behind this test.
741+
//Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
740742
Assert.True(_http1Connection.RequestAborted.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
741743

742744
Assert.Equal(originalToken, originalRegistration.Token);

0 commit comments

Comments
 (0)