Avoid Null ReferenceException in Frame.RequestAbortedSource
- Avoid unneeded resetting of _abortedCts and _manuallySetRequestAbortToken
This commit is contained in:
parent
6bff2ecb34
commit
d14f18012a
|
|
@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
private Task _requestProcessingTask;
|
private Task _requestProcessingTask;
|
||||||
protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx
|
protected volatile bool _requestProcessingStopping; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx
|
||||||
protected int _requestAborted;
|
protected int _requestAborted;
|
||||||
protected CancellationTokenSource _abortedCts;
|
private CancellationTokenSource _abortedCts;
|
||||||
protected CancellationToken? _manuallySetRequestAbortToken;
|
private CancellationToken? _manuallySetRequestAbortToken;
|
||||||
|
|
||||||
protected RequestProcessingStatus _requestProcessingStatus;
|
protected RequestProcessingStatus _requestProcessingStatus;
|
||||||
protected bool _keepAlive;
|
protected bool _keepAlive;
|
||||||
|
|
@ -196,7 +196,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
// Get the abort token, lazily-initializing it if necessary.
|
// Get the abort token, lazily-initializing it if necessary.
|
||||||
// Make sure it's canceled if an abort request already came in.
|
// Make sure it's canceled if an abort request already came in.
|
||||||
var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource());
|
|
||||||
|
// EnsureInitialized can return null since _abortedCts is reset to null
|
||||||
|
// after it's already been initialized to a non-null value.
|
||||||
|
// If EnsureInitialized does return null, this property was accessed between
|
||||||
|
// requests so it's safe to return an ephemeral CancellationTokenSource.
|
||||||
|
var cts = LazyInitializer.EnsureInitialized(ref _abortedCts, () => new CancellationTokenSource())
|
||||||
|
?? new CancellationTokenSource();
|
||||||
|
|
||||||
if (Volatile.Read(ref _requestAborted) == 1)
|
if (Volatile.Read(ref _requestAborted) == 1)
|
||||||
{
|
{
|
||||||
cts.Cancel();
|
cts.Cancel();
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
InitializeStreams(messageBody);
|
InitializeStreams(messageBody);
|
||||||
|
|
||||||
_abortedCts = null;
|
|
||||||
_manuallySetRequestAbortToken = null;
|
|
||||||
|
|
||||||
var context = _application.CreateContext(this);
|
var context = _application.CreateContext(this);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -164,8 +161,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
await TryProduceInvalidRequestResponse();
|
await TryProduceInvalidRequestResponse();
|
||||||
|
|
||||||
_abortedCts = null;
|
|
||||||
|
|
||||||
// If _requestAborted is set, the connection has already been closed.
|
// If _requestAborted is set, the connection has already been closed.
|
||||||
if (Volatile.Read(ref _requestAborted) == 0)
|
if (Volatile.Read(ref _requestAborted) == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue