Merge branch 'release/2.2'

This commit is contained in:
Nate McMaster 2019-01-24 16:14:55 -08:00 committed by GitHub
commit 5a0e227fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -26,7 +26,6 @@ Later on, this will be checked using this condition:
Microsoft.AspNetCore.Mvc.Core; Microsoft.AspNetCore.Mvc.Core;
Microsoft.AspNetCore.Routing; Microsoft.AspNetCore.Routing;
Microsoft.AspNetCore.Server.IIS; Microsoft.AspNetCore.Server.IIS;
Microsoft.AspNetCore.Server.Kestrel.Core;
java:signalr; java:signalr;
</PackagesInPatch> </PackagesInPatch>
</PropertyGroup> </PropertyGroup>

View File

@ -367,8 +367,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
// Lock to prevent CancelRequestAbortedToken from attempting to cancel an disposed CTS. // Lock to prevent CancelRequestAbortedToken from attempting to cancel an disposed CTS.
lock (_abortLock) lock (_abortLock)
{ {
_abortedCts?.Dispose(); if (!_requestAborted)
_abortedCts = null; {
_abortedCts?.Dispose();
_abortedCts = null;
}
} }
_requestHeadersParsed = 0; _requestHeadersParsed = 0;
@ -412,16 +415,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
private void CancelRequestAbortedToken() private void CancelRequestAbortedToken()
{ {
lock (_abortLock) try
{ {
try _abortedCts.Cancel();
{ _abortedCts.Dispose();
_abortedCts?.Cancel(); _abortedCts = null;
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.ApplicationError(ConnectionId, TraceIdentifier, ex); Log.ApplicationError(ConnectionId, TraceIdentifier, ex);
}
} }
} }
@ -435,12 +437,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
} }
_requestAborted = true; _requestAborted = true;
}
if (_abortedCts != null && !_preventRequestAbortedCancellation) if (_abortedCts != null)
{ {
// Potentially calling user code. CancelRequestAbortedToken logs any exceptions. // Potentially calling user code. CancelRequestAbortedToken logs any exceptions.
ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this); ServiceContext.Scheduler.Schedule(state => ((HttpProtocol)state).CancelRequestAbortedToken(), this);
}
} }
} }
@ -460,6 +462,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
} }
_preventRequestAbortedCancellation = true; _preventRequestAbortedCancellation = true;
_abortedCts?.Dispose();
_abortedCts = null;
} }
} }

View File

@ -729,14 +729,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
} }
[Fact] [Fact]
public void RequestAbortedTokenIsFullyUsableAfterCancellation() public void RequestAbortedTokenIsUsableAfterCancellation()
{ {
var originalToken = _http1Connection.RequestAborted; var originalToken = _http1Connection.RequestAborted;
var originalRegistration = originalToken.Register(() => { }); var originalRegistration = originalToken.Register(() => { });
_http1Connection.Abort(new ConnectionAbortedException()); _http1Connection.Abort(new ConnectionAbortedException());
Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout)); // The following line will throw an ODE because the original CTS backing the token has been diposed.
// See https://github.com/aspnet/AspNetCore/pull/4447 for the history behind this test.
//Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
Assert.True(_http1Connection.RequestAborted.WaitHandle.WaitOne(TestConstants.DefaultTimeout)); Assert.True(_http1Connection.RequestAborted.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
Assert.Equal(originalToken, originalRegistration.Token); Assert.Equal(originalToken, originalRegistration.Token);