diff --git a/config/config.default.json b/config/config.default.json index 0b75b0b..742fdc4 100644 --- a/config/config.default.json +++ b/config/config.default.json @@ -6,11 +6,12 @@ "matrixServerUrl": "http://localhost:8008/", "matrixServerName": "localhost", // Set this to 100 since that is the max that Synapse will backfill even if you do a - // `/messges?limit=1000` and we don't want to miss messages in between. + // `/messages?limit=1000` and we don't want to miss messages in between. "archiveMessageLimit": 100, "requestTimeoutMs": 25000, "logOutputFromChildProcesses": false, //"stopSearchEngineIndexing": true, + "workaroundCloudflare504TimeoutErrors": false, // Tracing //"jaegerTracesEndpoint": "http://localhost:14268/api/traces", diff --git a/server/middleware/timeout-middleware.js b/server/middleware/timeout-middleware.js index 3e0428d..0319555 100644 --- a/server/middleware/timeout-middleware.js +++ b/server/middleware/timeout-middleware.js @@ -102,8 +102,17 @@ async function timeoutMiddleware(req, res, next) { }, }); - // 504 Gateway timeout - res.status(504); + // The most semantic HTTP status code to return here is a 504 Gateway timeout but if + // you use Cloudflare in front of the archive, it will serve its own + // Cloudflare-branded 504 page if your own origin server responds with a 504. And + // the only way to disable this functionality is to have an Enterprise Cloudflare + // plan. So to workaround this, we return a 500 instead. Relevant Cloudflare docs: + // https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#502504-from-your-origin-web-server + // + // 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); + res.set('Content-Type', 'text/html'); res.send(pageHtml);