Skip to content

Write Premain errors to the response and write different status codes#10282

Merged
jkotalik merged 21 commits into
masterfrom
jkotalik/preMain
May 25, 2019
Merged

Write Premain errors to the response and write different status codes#10282
jkotalik merged 21 commits into
masterfrom
jkotalik/preMain

Conversation

@jkotalik
Copy link
Copy Markdown
Contributor

Fixes #10011 and will eventually fix #10008.

Here is so backstory behind how ANCM writes error pages, and my initial thoughts on how to design dynamic vs static responses.

When ANCM hits a startup exception in the shim or in the request handler, an error "Application" is created, which serves static HTML or the Hosting Startup Error page. This needs to be expanded now to serve dynamic content from hostfxr or potentially from ANCM. Along with checking if disableStartupErrorPage is set, writing text/plain vs text/html, status codes, substatus codes, etc, having a single application to handle multiple failure points has become unmanageable.

I think we should probably redesign how we server error responses. My initial idea was to create an ENUM or key off of HRESULT to know what type of error occurred, and change the type of application/handler to create. An example of this is what I did with hostfxr errors, where I create a new handler and application. I think the best approach is to create a unique application/handler per type of error which just serves a single type of failure. Then, per each failure type, we can add more dynamic data (like stack trace, hresult, doc link, etc.) when running in development. There may be a good amount of duplication, but trying to cram everything into the same class is getting worse and worse (see ServerApplication.cpp).

If this plan looks good, I'll go ahead and follow through. I just want to confirm with someone before I do a decently size refactoring.

@analogrelay analogrelay added this to the 3.0.0-preview6 milestone May 16, 2019
@jkotalik jkotalik changed the title Write Premain errors to the response and Log Write Premain errors to the response and write different status codes May 16, 2019
@jkotalik jkotalik force-pushed the jkotalik/preMain branch from a88f0b2 to c2fe895 Compare May 20, 2019 17:42
Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ShimOptions.cpp Outdated
@jkotalik jkotalik marked this pull request as ready for review May 21, 2019 23:09
@jkotalik jkotalik closed this May 21, 2019
@jkotalik jkotalik reopened this May 21, 2019
@jkotalik
Copy link
Copy Markdown
Contributor Author

Some feedback I received from @shirhatti is that the error pages need work with regards to looking different than the default error page (they look too similar). Currently errors look like this:
Capture

This does have the necessary information, but it isn't presented nicely. We can consider doing more work on this in either this PR or a separate PR.

Copy link
Copy Markdown
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass

Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp Outdated
Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp Outdated
Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp Outdated
Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp Outdated
Comment thread src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp Outdated
std::unique_ptr<IN_PROCESS_APPLICATION, IAPPLICATION_DELETER> inProcessApplication;

// TODO not sure how easy it will be to untangle errors here
// ErrorContext errorContext;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you figure out if it's possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but it isn't an important scenario. There are a few errors that can occur here, but they are very rare because we already invoked hostfxr earlier. After main has started, we would return the developer exception page.

USHORT m_subStatusCode;
std::string m_statusText;
std::vector<byte> m_ExceptionInfoContent;
std::string& m_ExceptionInfoContent;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just like to publicly say "I'm not a fan of this!"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocationsssss

@jkotalik
Copy link
Copy Markdown
Contributor Author

🆙 📅

Copy link
Copy Markdown
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Should anyone else be reviewing?

Comment thread src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp Outdated
Comment thread src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp Outdated
@jkotalik jkotalik merged commit 2d1c14d into master May 25, 2019
@ghost ghost deleted the jkotalik/preMain branch May 25, 2019 22:19
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ANCM] [in proc] Write pre-main errors to the browser when running in development Create new IIS sub-status code handler load failure

7 participants