Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYIC-7869: Spike - render service-unavailable page on 503 #1761

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Wynndow
Copy link
Contributor

@Wynndow Wynndow commented Dec 19, 2024

Proposed changes

What changed

Spike - render service-unavailable page on 503

Why did it change

The overload protection lib doesn't seem to be configurable to specify a template or html page to return when it kicks in. We can however set it to hand control back to the framework and handle a 503 ourselves.

The downside of this is that it will require the app to do work when it's already overloaded.

Issue tracking

The overload protection lib doesn't seem to be configurable to specify a
template or html page to return when it kicks in. We can however set it
to hand control back to the framework and handle a 503 ourselves.

The downside of this is that it will require the app to do work when
it's already overloaded.
@Wynndow Wynndow requested review from a team as code owners December 19, 2024 14:21
@Wynndow Wynndow marked this pull request as draft December 19, 2024 14:21
@@ -29,12 +29,16 @@ const serverErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
return next(err);
}

if (res.statusCode === 503) {
return res.render(getHtmlPath("errors", "service-unavailable-s3", ERROR_PAGES.SERVICE_UNAVAILABLE))
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah cool - I guess it's hard to tell whether routing through the error handlers will be substantially slower than the 'basic' response, but it feels like a worthwhile hit.

@@ -29,12 +29,16 @@ const serverErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
return next(err);
}

if (res.statusCode === 503) {
return res.render(getHtmlPath("errors", "service-unavailable-s3", ERROR_PAGES.SERVICE_UNAVAILABLE))
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't even realise we had this 503 page..! Perhaps once we get designs etc., we can build the page statically during the build process - something we'll worry about later.

@@ -29,12 +29,16 @@ const serverErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
return next(err);
}

if (res.statusCode === 503) {
return res.render(getHtmlPath("errors", "service-unavailable-s3", ERROR_PAGES.SERVICE_UNAVAILABLE))
Copy link
Contributor

@Joe-Edwards-GDS Joe-Edwards-GDS Dec 19, 2024

Choose a reason for hiding this comment

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

Do you know if this will cache the file or load it from disk each time? That's something we probably want to watch out for when implementing for real

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the look of it Express will cache views in production by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which is interesting because it implies that lower envs won't cache the views. Which might not help the results of the perf tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - I suspect it's looking for NODE_ENV=production, which should always be the case in deployed environments. :)

I wonder if we should be using res.send or res.sendFile instead? I'm not totally sure what the view engine will do with raw HTML 🤔 - presumably it works though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you're right - i just looked and it is production across the envs.

And yeah render works fine - but I guess there might be some perf gains for using send... I'll have a quick look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it looks like sendFile won't cache the file in memory - it'll read it from disk each time. So render might actually be a better choice, unless you want to introduce some other sort of caching.

Although I notice that we're globally setting Cache-control private no-store (among others) on all responses. Maybe if we allow caching, cloudfront will handle it for us?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - but we probably don't want CloudFront caching /page/ipv-success-page as a 503 error screen

If render 'just works' then that might be easiest. Otherwise we can load the file on startup and serve it from memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants