Merge pull request #22833 from dotnet-maestro-bot/merge/release/3.1-to-master

[automated] Merge branch 'release/3.1' => 'master'
This commit is contained in:
msftbot[bot] 2020-06-11 19:32:33 +00:00 committed by GitHub
commit 62e6d93f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 61 deletions

View File

@ -112,7 +112,7 @@ IN_PROCESS_HANDLER::NotifyDisconnect()
if (pManagedHttpContext != nullptr) if (pManagedHttpContext != nullptr)
{ {
m_pDisconnectHandler(m_pManagedHttpContext); m_pDisconnectHandler(pManagedHttpContext);
} }
} }
@ -139,14 +139,17 @@ IN_PROCESS_HANDLER::SetManagedHttpContext(
PVOID pManagedHttpContext PVOID pManagedHttpContext
) )
{ {
bool disconnectFired = false;
{ {
SRWExclusiveLock lock(m_srwDisconnectLock); SRWExclusiveLock lock(m_srwDisconnectLock);
m_pManagedHttpContext = pManagedHttpContext; m_pManagedHttpContext = pManagedHttpContext;
disconnectFired = m_disconnectFired;
} }
if (m_disconnectFired && m_pManagedHttpContext != nullptr) if (disconnectFired && pManagedHttpContext != nullptr)
{ {
m_pDisconnectHandler(m_pManagedHttpContext); m_pDisconnectHandler(pManagedHttpContext);
} }
} }

View File

@ -120,6 +120,11 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
public long? MaxRequestBodySize { get; set; } public long? MaxRequestBodySize { get; set; }
protected void InitializeContext() protected void InitializeContext()
{
// create a memory barrier between initialize and disconnect to prevent a possible
// NullRef with disconnect being called before these fields have been written
// disconnect aquires this lock as well
lock (_abortLock)
{ {
_thisHandle = GCHandle.Alloc(this); _thisHandle = GCHandle.Alloc(this);
@ -184,6 +189,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
resumeWriterThreshold: ResumeWriterTheshold, resumeWriterThreshold: ResumeWriterTheshold,
minimumSegmentSize: MinAllocBufferSize)); minimumSegmentSize: MinAllocBufferSize));
_bodyOutput = new OutputProducer(pipe); _bodyOutput = new OutputProducer(pipe);
}
NativeMethods.HttpSetManagedContext(_pInProcessHandler, (IntPtr)_thisHandle); NativeMethods.HttpSetManagedContext(_pInProcessHandler, (IntPtr)_thisHandle);
} }

View File

@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
try try
{ {
context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target; context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
context.AbortIO(clientDisconnect: true); context?.AbortIO(clientDisconnect: true);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
try try
{ {
context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target; context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
context.OnAsyncCompletion(hr, bytes); context?.OnAsyncCompletion(hr, bytes);
return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING; return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
} }
catch (Exception ex) catch (Exception ex)