Skip to content
代码片段 群组 项目
未验证 提交 7d4ae604 编辑于 作者: Stephen Halter's avatar Stephen Halter 提交者: GitHub
浏览文件

Revert "Revert "Wait to dispose RequestAborted CTS (#4447)"" (#6812)

This reverts commit 29b7c5c0.
上级 9c017cd8
No related branches found
No related tags found
无相关合并请求
...@@ -26,6 +26,7 @@ Later on, this will be checked using this condition: ...@@ -26,6 +26,7 @@ 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>
......
...@@ -367,11 +367,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ...@@ -367,11 +367,8 @@ 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)
{ {
if (!_requestAborted) _abortedCts?.Dispose();
{ _abortedCts = null;
_abortedCts?.Dispose();
_abortedCts = null;
}
} }
_requestHeadersParsed = 0; _requestHeadersParsed = 0;
...@@ -415,15 +412,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ...@@ -415,15 +412,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
private void CancelRequestAbortedToken() private void CancelRequestAbortedToken()
{ {
try lock (_abortLock)
{
_abortedCts.Cancel();
_abortedCts.Dispose();
_abortedCts = null;
}
catch (Exception ex)
{ {
Log.ApplicationError(ConnectionId, TraceIdentifier, ex); try
{
_abortedCts?.Cancel();
}
catch (Exception ex)
{
Log.ApplicationError(ConnectionId, TraceIdentifier, ex);
}
} }
} }
...@@ -437,12 +435,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ...@@ -437,12 +435,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
} }
_requestAborted = true; _requestAborted = true;
}
if (_abortedCts != null) if (_abortedCts != null && !_preventRequestAbortedCancellation)
{ {
// 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);
}
} }
} }
...@@ -462,8 +460,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http ...@@ -462,8 +460,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
} }
_preventRequestAbortedCancellation = true; _preventRequestAbortedCancellation = true;
_abortedCts?.Dispose();
_abortedCts = null;
} }
} }
......
...@@ -53,7 +53,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ...@@ -53,7 +53,11 @@ 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
{ {
...@@ -724,6 +728,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests ...@@ -724,6 +728,20 @@ 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));
Assert.Equal(originalToken, originalRegistration.Token);
}
[Fact] [Fact]
public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled() public async Task ExceptionDetailNotIncludedWhenLogLevelInformationNotEnabled()
{ {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册