Skip to content

Commit 9717ec3

Browse files
committed
Revert "Removing copy on shutdown"
This reverts commit b4ea78a.
1 parent 0ed2ab3 commit 9717ec3

File tree

13 files changed

+39
-37
lines changed

13 files changed

+39
-37
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ APPLICATION_INFO::CreateApplication(IHttpContext& pHttpContext)
9393
errorContext.statusCode = 500i16;
9494
errorContext.subStatusCode = 0i16;
9595

96+
9697
const auto hr = TryCreateApplication(pHttpContext, options, errorContext);
9798

9899
if (FAILED_LOG(hr))

src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/inprocess_application_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace InprocessTests
3939
{"InProcessExeLocation", exePath.data()}
4040
};
4141

42-
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), parameters.data(), 1, std::wstring());
42+
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), parameters.data(), 1);
4343

4444
ASSERT_STREQ(app->QueryExeLocation().c_str(), L"hello");
4545
}
@@ -59,7 +59,7 @@ namespace InprocessTests
5959
.WillByDefault(testing::Return(L""));
6060

6161
auto requestHandlerConfig = std::unique_ptr<InProcessOptions>(MockInProcessOptions::CreateConfig());
62-
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), nullptr, 0, std::wstring());
62+
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), nullptr, 0);
6363

6464
ASSERT_STREQ(app->QueryApplicationVirtualPath().c_str(), L"/SECTION5");
6565
}
@@ -79,7 +79,7 @@ namespace InprocessTests
7979
.WillByDefault(testing::Return(L""));
8080

8181
auto requestHandlerConfig = std::unique_ptr<InProcessOptions>(MockInProcessOptions::CreateConfig());
82-
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), nullptr, 0, std::wstring());
82+
IN_PROCESS_APPLICATION *app = new IN_PROCESS_APPLICATION(server, application, std::move(requestHandlerConfig), nullptr, 0);
8383

8484
ASSERT_STREQ(app->QueryApplicationVirtualPath().c_str(), L"/");
8585
}

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class ShuttingDownHandler : public REQUEST_HANDLER
3131
class ShuttingDownApplication : public InProcessApplicationBase
3232
{
3333
public:
34-
ShuttingDownApplication(IHttpServer& pHttpServer, IHttpApplication& pHttpApplication, std::wstring shadowCopy)
35-
: InProcessApplicationBase(pHttpServer, pHttpApplication, shadowCopy)
34+
ShuttingDownApplication(IHttpServer& pHttpServer, IHttpApplication& pHttpApplication)
35+
: InProcessApplicationBase(pHttpServer, pHttpApplication, std::wstring())
3636
{
3737
}
3838

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class StartupExceptionApplication : public InProcessApplicationBase
1818
const std::string& errorPageContent,
1919
USHORT statusCode,
2020
USHORT subStatusCode,
21-
const std::string& statusText,
22-
std::wstring shadowCopy)
21+
const std::string& statusText)
2322
: m_disableLogs(disableLogs),
2423
m_HR(hr),
2524
m_error(errorPageContent),
2625
m_statusCode(statusCode),
2726
m_subStatusCode(subStatusCode),
2827
m_statusText(std::move(statusText)),
29-
InProcessApplicationBase(pServer, pApplication, shadowCopy)
28+
InProcessApplicationBase(pServer, pApplication, std::wstring())
3029
{
3130
}
3231

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ CreateApplication(
103103
{
104104
TraceContextScope traceScope(FindParameter<IHttpTraceContext*>("TraceContext", pParameters, nParameters));
105105
const auto pSite = FindParameter<IHttpSite*>("Site", pParameters, nParameters);
106-
const auto shadowCopyPtr = FindParameter<PCWSTR>("ShadowCopyDirectory", pParameters, nParameters);
107106

108107
try
109108
{
@@ -114,7 +113,7 @@ CreateApplication(
114113
// means that server is shutting does and request arrived in the meantime
115114
if (g_fInProcessApplicationCreated)
116115
{
117-
*ppApplication = new ShuttingDownApplication(*pServer, *pHttpApplication, shadowCopyPtr);
116+
*ppApplication = new ShuttingDownApplication(*pServer, *pHttpApplication);
118117
return S_OK;
119118
}
120119

@@ -129,7 +128,7 @@ CreateApplication(
129128
errorContext.generalErrorType = "ASP.NET Core app failed to start";
130129
errorContext.errorReason = "<ul><li>The app failed to start</li><li>The app started but then stopped</li><li>The app started but threw an exception during startup</li></ul>";
131130

132-
if (!FAILED_LOG(hr = IN_PROCESS_APPLICATION::Start(*pServer, pSite, *pHttpApplication, pParameters, nParameters, inProcessApplication, errorContext, shadowCopyPtr)))
131+
if (!FAILED_LOG(hr = IN_PROCESS_APPLICATION::Start(*pServer, pSite, *pHttpApplication, pParameters, nParameters, inProcessApplication, errorContext)))
133132
{
134133
*ppApplication = inProcessApplication.release();
135134
}
@@ -155,8 +154,7 @@ CreateApplication(
155154
content,
156155
errorContext.statusCode,
157156
errorContext.subStatusCode,
158-
"Internal Server Error",
159-
shadowCopyPtr);
157+
"Internal Server Error");
160158

161159
RETURN_IF_FAILED(pErrorApplication->StartMonitoringAppOffline());
162160
*ppApplication = pErrorApplication.release();

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION(
2121
IHttpApplication& pApplication,
2222
std::unique_ptr<InProcessOptions> pConfig,
2323
APPLICATION_PARAMETER* pParameters,
24-
DWORD nParameters,
25-
std::wstring shadowCopy) :
26-
InProcessApplicationBase(pHttpServer, pApplication, shadowCopy),
24+
DWORD nParameters) :
25+
InProcessApplicationBase(pHttpServer,
26+
pApplication,
27+
FindParameter<PCWSTR>("ShadowCopyDirectory", pParameters, nParameters)),
2728
m_Initialized(false),
2829
m_blockManagedCallbacks(true),
2930
m_waitForShutdown(true),
@@ -249,7 +250,7 @@ IN_PROCESS_APPLICATION::ExecuteApplication()
249250
LOG_INFOF(L"Setting dll directory to %s", currentDirectory.c_str());
250251
}
251252

252-
// Keep as original directory
253+
// I think I still want this to be the current directory
253254
LOG_LAST_ERROR_IF(!SetCurrentDirectory(this->QueryApplicationPhysicalPath().c_str()));
254255

255256
LOG_INFOF(L"Setting current directory to %s", this->QueryApplicationPhysicalPath().c_str());
@@ -413,15 +414,14 @@ HRESULT IN_PROCESS_APPLICATION::Start(
413414
APPLICATION_PARAMETER* pParameters,
414415
DWORD nParameters,
415416
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application,
416-
ErrorContext& errorContext,
417-
std::wstring shadowCopy)
417+
ErrorContext& errorContext)
418418
{
419419
try
420420
{
421421
std::unique_ptr<InProcessOptions> options;
422422
THROW_IF_FAILED(InProcessOptions::Create(pServer, pSite, pHttpApplication, options));
423423
application = std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>(
424-
new IN_PROCESS_APPLICATION(pServer, pHttpApplication, std::move(options), pParameters, nParameters, shadowCopy));
424+
new IN_PROCESS_APPLICATION(pServer, pHttpApplication, std::move(options), pParameters, nParameters));
425425
THROW_IF_FAILED(application->LoadManagedApplication(errorContext));
426426
return S_OK;
427427
}

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class IN_PROCESS_APPLICATION : public InProcessApplicationBase
2323
IHttpApplication& pApplication,
2424
std::unique_ptr<InProcessOptions> pConfig,
2525
APPLICATION_PARAMETER *pParameters,
26-
DWORD nParameters,
27-
std::wstring shadowCopy);
26+
DWORD nParameters);
2827

2928
~IN_PROCESS_APPLICATION();
3029

@@ -115,8 +114,7 @@ class IN_PROCESS_APPLICATION : public InProcessApplicationBase
115114
APPLICATION_PARAMETER* pParameters,
116115
DWORD nParameters,
117116
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application,
118-
ErrorContext& errorContext,
119-
std::wstring shadowCopy);
117+
ErrorContext& errorContext);
120118

121119
private:
122120
struct ExecuteClrContext: std::enable_shared_from_this<ExecuteClrContext>
@@ -180,6 +178,7 @@ class IN_PROCESS_APPLICATION : public InProcessApplicationBase
180178

181179
inline static const LPCSTR s_exeLocationParameterName = "InProcessExeLocation";
182180

181+
183182
VOID
184183
UnexpectedThreadExit(const ExecuteClrContext& context) const;
185184

src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ CreateApplication(
252252
{
253253
TraceContextScope traceScope(FindParameter<IHttpTraceContext*>("TraceContext", pParameters, nParameters));
254254
auto pSite = FindParameter<IHttpSite*>("Site", pParameters, nParameters);
255-
auto shadowCopy = FindParameter<PCWSTR> ("ShadowCopyDirectory", pParameters, nParameters);
256255

257256
InitializeGlobalConfiguration(pServer);
258257

@@ -262,7 +261,7 @@ CreateApplication(
262261

263262
RETURN_IF_FAILED(EnsureOutOfProcessInitializtion(pHttpApplication));
264263

265-
std::unique_ptr<OUT_OF_PROCESS_APPLICATION> pApplication = std::make_unique<OUT_OF_PROCESS_APPLICATION>(*pHttpApplication, std::move(pRequestHandlerConfig), shadowCopy);
264+
std::unique_ptr<OUT_OF_PROCESS_APPLICATION> pApplication = std::make_unique<OUT_OF_PROCESS_APPLICATION>(*pHttpApplication, std::move(pRequestHandlerConfig));
266265

267266
RETURN_IF_FAILED(pApplication->Initialize());
268267
RETURN_IF_FAILED(pApplication->StartMonitoringAppOffline());

src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
OUT_OF_PROCESS_APPLICATION::OUT_OF_PROCESS_APPLICATION(
99
IHttpApplication& pApplication,
10-
std::unique_ptr<REQUESTHANDLER_CONFIG> pConfig,
11-
std::wstring shadowCopy) :
12-
AppOfflineTrackingApplication(pApplication, shadowCopy),
10+
std::unique_ptr<REQUESTHANDLER_CONFIG> pConfig) :
11+
AppOfflineTrackingApplication(pApplication, std::wstring()),
1312
m_fWebSocketSupported(WEBSOCKET_STATUS::WEBSOCKET_UNKNOWN),
1413
m_pConfig(std::move(pConfig))
1514
{

src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class OUT_OF_PROCESS_APPLICATION : public AppOfflineTrackingApplication
1717
public:
1818
OUT_OF_PROCESS_APPLICATION(
1919
IHttpApplication& pApplication,
20-
std::unique_ptr<REQUESTHANDLER_CONFIG> pConfig,
21-
std::wstring shadowCopy);
20+
std::unique_ptr<REQUESTHANDLER_CONFIG> pConfig);
2221

2322
__override
2423
~OUT_OF_PROCESS_APPLICATION() override;

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ HRESULT AppOfflineTrackingApplication::StartMonitoringAppOflineImpl()
4545
RETURN_IF_FAILED(m_fileWatcher->Create(m_applicationPath.c_str(),
4646
L"app_offline.htm",
4747
/* fTrackDllChanges */ !m_shadowCopyDirectory.empty(),
48+
m_shadowCopyDirectory,
4849
this));
4950

5051
return S_OK;

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FILE_WATCHER::FILE_WATCHER() :
1818
FILE_WATCHER::~FILE_WATCHER()
1919
{
2020
StopMonitor();
21-
WaitForMonitor(100);
21+
WaitForMonitor(20);
2222
}
2323

2424
void FILE_WATCHER::WaitForMonitor(DWORD dwRetryCounter)
@@ -59,9 +59,11 @@ FILE_WATCHER::Create(
5959
_In_ PCWSTR pszDirectoryToMonitor,
6060
_In_ PCWSTR pszFileNameToMonitor,
6161
_In_ bool fTrackDllChanges,
62+
_In_ std::wstring shadowCopyPath,
6263
_In_ AppOfflineTrackingApplication *pApplication
6364
)
6465
{
66+
_shadowCopyPath = shadowCopyPath;
6567
RETURN_LAST_ERROR_IF_NULL(m_hCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0));
6668

6769
RETURN_LAST_ERROR_IF_NULL(m_hChangeNotificationThread = CreateThread(NULL,
@@ -286,12 +288,15 @@ HRESULT
286288
{
287289
// Reference application before
288290
_pApplication->ReferenceApplication();
289-
//if (fDllChanged)
290-
//{
291-
// // wait for all file changes to complete
292-
// PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, NULL);
293-
//}
291+
if (fDllChanged)
292+
{
293+
// wait for all file changes to complete
294+
PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, NULL);
295+
WaitForMonitor(100); // 5 seconds here.
294296

297+
// Copy contents before shutdown
298+
RETURN_IF_FAILED(Environment::CopyToDirectory(_shadowCopyPath, _strDirectoryName.QueryStr(), false));
299+
}
295300
RETURN_LAST_ERROR_IF(!QueueUserWorkItem(RunNotificationCallback, _pApplication.get(), WT_EXECUTEDEFAULT));
296301
}
297302

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class FILE_WATCHER{
2929
_In_ PCWSTR pszDirectoryToMonitor,
3030
_In_ PCWSTR pszFileNameToMonitor,
3131
_In_ bool fTrackDllChanges,
32+
_In_ std::wstring shadowCopyPath,
3233
_In_ AppOfflineTrackingApplication *pApplication
3334
);
3435

@@ -57,6 +58,7 @@ class FILE_WATCHER{
5758
STRU _strFullName;
5859
LONG _lStopMonitorCalled {};
5960
bool _fTrackDllChanges;
61+
std::wstring _shadowCopyPath;
6062
OVERLAPPED _overlapped;
6163
std::unique_ptr<AppOfflineTrackingApplication, IAPPLICATION_DELETER> _pApplication;
6264
};

0 commit comments

Comments
 (0)