Revert "Wait to dispose RequestAborted CTS (#4447)"
This reverts commit 0622513058.
This commit is contained in:
parent
f4c5ac7635
commit
5d554aeecd
|
|
@ -36,7 +36,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>
|
||||||
|
|
|
||||||
|
|
@ -348,8 +348,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;
|
||||||
|
|
@ -391,16 +394,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);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,12 +416,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);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,6 +441,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
}
|
}
|
||||||
|
|
||||||
_preventRequestAbortedCancellation = true;
|
_preventRequestAbortedCancellation = true;
|
||||||
|
_abortedCts?.Dispose();
|
||||||
|
_abortedCts = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,11 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
var connectionFeatures = new FeatureCollection();
|
var connectionFeatures = new FeatureCollection();
|
||||||
connectionFeatures.Set(Mock.Of<IConnectionLifetimeFeature>());
|
connectionFeatures.Set(Mock.Of<IConnectionLifetimeFeature>());
|
||||||
|
|
||||||
_serviceContext = new TestServiceContext()
|
_serviceContext = new TestServiceContext();
|
||||||
{
|
|
||||||
Scheduler = PipeScheduler.Inline
|
|
||||||
};
|
|
||||||
|
|
||||||
_timeoutControl = new Mock<ITimeoutControl>();
|
_timeoutControl = new Mock<ITimeoutControl>();
|
||||||
_http1ConnectionContext = new HttpConnectionContext
|
_http1ConnectionContext = new HttpConnectionContext
|
||||||
{
|
{
|
||||||
|
|
@ -728,25 +724,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
Assert.False(_http1Connection.RequestAborted.IsCancellationRequested);
|
Assert.False(_http1Connection.RequestAborted.IsCancellationRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestAbortedTokenIsFullyUsableAfterCancellation()
|
|
||||||
{
|
|
||||||
var originalToken = _http1Connection.RequestAborted;
|
|
||||||
var originalRegistration = originalToken.Register(() => { });
|
|
||||||
|
|
||||||
_http1Connection.Abort(new ConnectionAbortedException());
|
|
||||||
|
|
||||||
Assert.True(originalToken.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
|
|
||||||
Assert.True(_http1Connection.RequestAborted.WaitHandle.WaitOne(TestConstants.DefaultTimeout));
|
|
||||||
|
|
||||||
#if NETCOREAPP2_2
|
|
||||||
Assert.Equal(originalToken, originalRegistration.Token);
|
|
||||||
#elif NET461
|
|
||||||
#else
|
|
||||||
#error Target framework needs to be updated
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled()
|
public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue