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

Consider prohibiting or avoiding responses with a 502 Bad Gateway and 504 Gateway Timeout HTTP status code #1034

Closed
DMRobertson opened this issue Apr 25, 2022 · 2 comments

Comments

@DMRobertson
Copy link
Contributor

The only such specced response I can see is https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3downloadservernamemediaid. (I only checked C-S and S-S APIs).

Suppose a homeserver responds with 502 or 504 behind Cloudflare. Cloudflare will serve their own HTML error page instead of the JSON data from the homeserver. We've seen examples of this where a response like

{"errcode":"M_UNKNOWN","error":"blah blah blah"}

is rewritten and presented to clients as

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<meta http-equiv="refresh" content="0">

<title>[matrix.org](http://matrix.org/) | 502: Bad gateway</title>
...

which means the client can only present a generic "unknown error" at best.

I don't want to make the spec bound to the whims of any particular reverse proxy service, but for pragmatism's sake it might be worth considering

  • a different way to express "The content is too large for the server to serve." for this endpoint
  • a prohibition of any 502s and 504s response codes in the future.
@DMRobertson
Copy link
Contributor Author

Additionally: https://support.cloudflare.com/hc/en-us/articles/200172706-Configuring-Custom-Pages-Error-and-Challenge- writes:

500, 501, 503, and 505 responses do not trigger custom error pages to avoid breaking specific API endpoints and other web applications.

These are respectively: Internal Server Error, Not Implemented, Service Unavailable, and HTTP Version Not Supported.

@turt2live
Copy link
Member

I'd argue that 502 is a valid error code in some circumstances for how the media repo is behaving, and wouldn't prohibit its use for those circumstances despite CloudFlare. Other error codes appear inappropriate when the homeserver is acting as a proxy to another server.

I've opened #1095 to track the issue with the media download endpoint, however I don't think we can reasonably prevent the use of the 502 error code at this time.

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

No branches or pull requests

2 participants