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

Prevent Cloudflare from overriding our own 504 timeout page #228

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented May 11, 2023

Prevent Cloudflare from overriding our own 504 timeout page

Explored in https://gitlab.matrix.org/matrix-public-archive/deployment/-/issues/2 (internal deployment issue)

Cloudflare returns an Cloudflare-branded HTTP 502 or 504 error when your origin web server responds with a standard HTTP 502 bad gateway or 504 gateway timeout error:

-- https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#502504-from-your-origin-web-server

The only way to disable this functionality is to have an Enterprise Cloudflare plan and use the Enable Origin Error Pages option:

Enable Origin Error Pages

When Origin Error Page is set to “On”, Cloudflare will proxy the 502 and 504 error pages directly from the origin.

Requires Enterprise or higher

So instead of dealing with that headache, we're just working around this by responding with a 500 error when we timeout. Should be good enough I think. The user won't know any difference but may affect what Search Engines think. Not sure search engines care about the distinction since the page is slow to respond anyway which they punish.

Explored in https://gitlab.matrix.org/matrix-public-archive/deployment/-/issues/2

> Cloudflare returns an Cloudflare-branded HTTP 502 or 504 error when your origin web server responds with a standard HTTP 502 bad gateway or 504 gateway timeout error:
>
> *-- https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#502504-from-your-origin-web-server*

The only way to disable this functionality is to have an Enterprise Cloudflare plan and use the `Enable Origin Error Pages` option:

> Enable Origin Error Pages
>
> When Origin Error Page is set to “On”, Cloudflare will proxy the 502 and 504 error pages directly from the origin.
>
> Requires Enterprise or higher

So instead of dealing with that headache, we're just working around this by
responding with a 500 error when we timeout. Should be good enough I think.
The user won't know any difference but may affect what Search Engines think.
Not sure they care about the distinction since the page is slow to respond
anyway which they punish.
@MadLittleMods MadLittleMods added T-Defect Something isn't working. Bugs, crashes, or other reported issues. A-archive-room-view The view to look at a room day by day in the archive labels May 11, 2023
@MadLittleMods MadLittleMods marked this pull request as ready for review May 11, 2023 21:20
@MadLittleMods MadLittleMods merged commit 55f1867 into main May 11, 2023
6 checks passed
//
// We want to show our own timeout page because it has more information about what
// went wrong (e.g. which external Matrix API requests were slow).
res.status(config.workaroundCloudflare504TimeoutErrors ? 500 : 504);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be using config.get('workaroundCloudflare504TimeoutErrors')

Fixed in #229

MadLittleMods added a commit that referenced this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-archive-room-view The view to look at a room day by day in the archive T-Defect Something isn't working. Bugs, crashes, or other reported issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant