Log StartupTimeoutLimit failure to response (#10661)

This commit is contained in:
Justin Kotalik 2019-05-31 08:59:42 -07:00 committed by GitHub
parent 62c190da6e
commit 69139b5023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 16 deletions

View File

@ -122,10 +122,13 @@ CreateApplication(
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER> inProcessApplication; std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER> inProcessApplication;
// TODO not sure how easy it will be to untangle errors here ErrorContext errorContext;
// ErrorContext errorContext; errorContext.statusCode = 500;
errorContext.subStatusCode = 30;
errorContext.generalErrorType = "ANCM In-Process Start Failure";
errorContext.errorReason = "<ul><li>The application failed to start</li><li>The application started but then stopped</li><li>The application started but threw an exception during startup</li></ul>";
if (!FAILED_LOG(hr = IN_PROCESS_APPLICATION::Start(*pServer, pSite, *pHttpApplication, pParameters, nParameters, inProcessApplication))) if (!FAILED_LOG(hr = IN_PROCESS_APPLICATION::Start(*pServer, pSite, *pHttpApplication, pParameters, nParameters, inProcessApplication, errorContext)))
{ {
*ppApplication = inProcessApplication.release(); *ppApplication = inProcessApplication.release();
} }
@ -138,10 +141,10 @@ CreateApplication(
g_errorPageContent : g_errorPageContent :
FILE_UTILITY::GetHtml(g_hServerModule, FILE_UTILITY::GetHtml(g_hServerModule,
IN_PROCESS_RH_STATIC_HTML, IN_PROCESS_RH_STATIC_HTML,
500i16, errorContext.statusCode,
30i16, errorContext.subStatusCode,
"ANCM In-Process Start Failure", errorContext.generalErrorType,
"<ul><li>The application failed to start</li><li>The application started but then stopped</li><li>The application started but threw an exception during startup</li></ul>", errorContext.errorReason,
""); "");
auto pErrorApplication = std::make_unique<StartupExceptionApplication>(*pServer, auto pErrorApplication = std::make_unique<StartupExceptionApplication>(*pServer,
@ -149,8 +152,8 @@ CreateApplication(
options->QueryDisableStartUpErrorPage(), options->QueryDisableStartUpErrorPage(),
hr, hr,
content, content,
500i16, errorContext.statusCode,
30i16, errorContext.subStatusCode,
"Internal Server Error"); "Internal Server Error");
RETURN_IF_FAILED(pErrorApplication->StartMonitoringAppOffline()); RETURN_IF_FAILED(pErrorApplication->StartMonitoringAppOffline());

View File

@ -130,7 +130,7 @@ IN_PROCESS_APPLICATION::SetCallbackHandles(
} }
HRESULT HRESULT
IN_PROCESS_APPLICATION::LoadManagedApplication() IN_PROCESS_APPLICATION::LoadManagedApplication(ErrorContext& errorContext)
{ {
THROW_LAST_ERROR_IF_NULL(m_pInitializeEvent = CreateEvent( THROW_LAST_ERROR_IF_NULL(m_pInitializeEvent = CreateEvent(
nullptr, // default security attributes nullptr, // default security attributes
@ -157,11 +157,17 @@ IN_PROCESS_APPLICATION::LoadManagedApplication()
// Wait for shutdown request // Wait for shutdown request
const auto waitResult = WaitForMultipleObjects(2, waitHandles, FALSE, m_pConfig->QueryStartupTimeLimitInMS()); const auto waitResult = WaitForMultipleObjects(2, waitHandles, FALSE, m_pConfig->QueryStartupTimeLimitInMS());
THROW_LAST_ERROR_IF(waitResult == WAIT_FAILED); THROW_LAST_ERROR_IF(waitResult == WAIT_FAILED);
if (waitResult == WAIT_TIMEOUT) if (waitResult == WAIT_TIMEOUT)
{ {
// If server wasn't initialized in time shut application down without waiting for CLR thread to exit // If server wasn't initialized in time shut application down without waiting for CLR thread to exit
errorContext.statusCode = 500;
errorContext.subStatusCode = 37;
errorContext.generalErrorType = "ANCM Failed to Start Within Startup Time Limit";
errorContext.errorReason = format("ANCM failed to start after %d milliseconds", m_pConfig->QueryStartupTimeLimitInMS());
m_waitForShutdown = false; m_waitForShutdown = false;
StopClr(); StopClr();
throw InvalidOperationException(format(L"Managed server didn't initialize after %u ms.", m_pConfig->QueryStartupTimeLimitInMS())); throw InvalidOperationException(format(L"Managed server didn't initialize after %u ms.", m_pConfig->QueryStartupTimeLimitInMS()));
@ -380,7 +386,8 @@ HRESULT IN_PROCESS_APPLICATION::Start(
IHttpApplication& pHttpApplication, IHttpApplication& pHttpApplication,
APPLICATION_PARAMETER* pParameters, APPLICATION_PARAMETER* pParameters,
DWORD nParameters, DWORD nParameters,
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application) std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application,
ErrorContext& errorContext)
{ {
try try
{ {
@ -388,7 +395,7 @@ HRESULT IN_PROCESS_APPLICATION::Start(
THROW_IF_FAILED(InProcessOptions::Create(pServer, pSite, pHttpApplication, options)); THROW_IF_FAILED(InProcessOptions::Create(pServer, pSite, pHttpApplication, options));
application = std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>( application = std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>(
new IN_PROCESS_APPLICATION(pServer, pHttpApplication, std::move(options), pParameters, nParameters)); new IN_PROCESS_APPLICATION(pServer, pHttpApplication, std::move(options), pParameters, nParameters));
THROW_IF_FAILED(application->LoadManagedApplication()); THROW_IF_FAILED(application->LoadManagedApplication(errorContext));
return S_OK; return S_OK;
} }
catch (InvalidOperationException& ex) catch (InvalidOperationException& ex)

View File

@ -58,7 +58,7 @@ public:
ExecuteApplication(); ExecuteApplication();
HRESULT HRESULT
LoadManagedApplication(); LoadManagedApplication(ErrorContext& errorContext);
void void
QueueStop(); QueueStop();
@ -115,7 +115,8 @@ public:
IHttpApplication& pHttpApplication, IHttpApplication& pHttpApplication,
APPLICATION_PARAMETER* pParameters, APPLICATION_PARAMETER* pParameters,
DWORD nParameters, DWORD nParameters,
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application); std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER>& application,
ErrorContext& errorContext);
private: private:
struct ExecuteClrContext: std::enable_shared_from_this<ExecuteClrContext> struct ExecuteClrContext: std::enable_shared_from_this<ExecuteClrContext>

View File

@ -416,7 +416,6 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.InProcess
} }
[ConditionalFact] [ConditionalFact]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/1772", FlakyOn.All)]
public async Task StartupTimeoutIsApplied() public async Task StartupTimeoutIsApplied()
{ {
// From what I can tell, this failure is due to ungraceful shutdown. // From what I can tell, this failure is due to ungraceful shutdown.
@ -434,11 +433,17 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.InProcess
var response = await deploymentResult.HttpClient.GetAsync("/"); var response = await deploymentResult.HttpClient.GetAsync("/");
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
StopServer(); StopServer(gracefulShutdown: false);
EventLogHelpers.VerifyEventLogEvents(deploymentResult, EventLogHelpers.VerifyEventLogEvents(deploymentResult,
EventLogHelpers.InProcessFailedToStart(deploymentResult, "Managed server didn't initialize after 1000 ms.") EventLogHelpers.InProcessFailedToStart(deploymentResult, "Managed server didn't initialize after 1000 ms.")
); );
if (DeployerSelector.HasNewHandler)
{
var responseContent = await response.Content.ReadAsStringAsync();
Assert.Contains("ANCM Failed to Start Within Startup Time Limit", responseContent);
}
} }
} }