Guard OnAsyncCompletion from completing request before OnExecuteRequestHandler exits (#1489)

This commit is contained in:
Pavel Krymets 2018-10-10 14:34:55 -07:00 committed by GitHub
parent ab124fc344
commit bfa583a9aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "applicationinfo.h" #include "applicationinfo.h"
#include "exceptions.h" #include "exceptions.h"
#include "DisconnectHandler.h" #include "DisconnectHandler.h"
#include "SRWExclusiveLock.h"
extern BOOL g_fInShutdown; extern BOOL g_fInShutdown;
@ -67,6 +68,7 @@ ASPNET_CORE_PROXY_MODULE::ASPNET_CORE_PROXY_MODULE(HTTP_MODULE_ID moduleId, std:
m_moduleId(moduleId), m_moduleId(moduleId),
m_pDisconnectHandler(nullptr) m_pDisconnectHandler(nullptr)
{ {
InitializeSRWLock(&m_requestLock);
} }
ASPNET_CORE_PROXY_MODULE::~ASPNET_CORE_PROXY_MODULE() ASPNET_CORE_PROXY_MODULE::~ASPNET_CORE_PROXY_MODULE()
@ -84,6 +86,9 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
HRESULT hr = S_OK; HRESULT hr = S_OK;
REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE; REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE;
// We don't want OnAsyncCompletion to complete request before OnExecuteRequestHandler exits
auto lock = SRWExclusiveLock(m_requestLock);
try try
{ {
if (g_fInShutdown) if (g_fInShutdown)
@ -134,6 +139,9 @@ ASPNET_CORE_PROXY_MODULE::OnAsyncCompletion(
IHttpCompletionInfo * pCompletionInfo IHttpCompletionInfo * pCompletionInfo
) )
{ {
// We don't want OnAsyncCompletion to complete request before OnExecuteRequestHandler exits
auto lock = SRWExclusiveLock(m_requestLock);
try try
{ {
return HandleNotificationStatus(m_pHandler->OnAsyncCompletion( return HandleNotificationStatus(m_pHandler->OnAsyncCompletion(

View File

@ -60,6 +60,7 @@ class ASPNET_CORE_PROXY_MODULE : NonCopyable, public CHttpModule
std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> m_pHandler; std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> m_pHandler;
HTTP_MODULE_ID m_moduleId; HTTP_MODULE_ID m_moduleId;
DisconnectHandler * m_pDisconnectHandler; DisconnectHandler * m_pDisconnectHandler;
SRWLOCK m_requestLock {};
}; };
class ASPNET_CORE_PROXY_MODULE_FACTORY : NonCopyable, public IHttpModuleFactory class ASPNET_CORE_PROXY_MODULE_FACTORY : NonCopyable, public IHttpModuleFactory