From 47820c61a0939b3a5094cb203890630620d2270d Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 24 Oct 2023 15:28:37 +0200 Subject: [PATCH] Merge pull request #15409 from overleaf/jpa-history-v1-http-timeout [history-v1] make http request timeout configurable GitOrigin-RevId: b31b1c94563ddb5195f92af303e6b0f234856795 --- server-ce/config/custom-environment-variables.json | 3 ++- server-ce/config/settings.js | 4 ++++ services/history-v1/app.js | 5 +++-- services/history-v1/config/custom-environment-variables.json | 3 ++- services/history-v1/config/default.json | 3 ++- services/project-history/app/js/HistoryStoreManager.js | 2 +- services/project-history/config/settings.defaults.cjs | 3 +++ .../unit/js/HistoryStoreManager/HistoryStoreManagerTests.js | 1 + 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server-ce/config/custom-environment-variables.json b/server-ce/config/custom-environment-variables.json index 1f05548ecb..3bb0c0f15a 100644 --- a/server-ce/config/custom-environment-variables.json +++ b/server-ce/config/custom-environment-variables.json @@ -43,5 +43,6 @@ }, "clusterWorkers": "CLUSTER_WORKERS", "maxFileUploadSize": "MAX_FILE_UPLOAD_SIZE", - "httpsOnly": "HTTPS_ONLY" + "httpsOnly": "HTTPS_ONLY", + "httpRequestTimeout": "SHARELATEX_HISTORY_V1_HTTP_REQUEST_TIMEOUT" } diff --git a/server-ce/config/settings.js b/server-ce/config/settings.js index 3505b20ddf..a4bea36ced 100644 --- a/server-ce/config/settings.js +++ b/server-ce/config/settings.js @@ -261,6 +261,10 @@ const settings = { url: process.env.V1_HISTORY_URL || 'http://localhost:3100/api', user: 'staging', pass: process.env.STAGING_PASSWORD, + requestTimeout: parseInt( + process.env.SHARELATEX_HISTORY_V1_HTTP_REQUEST_TIMEOUT || '300000', // default is 5min + 10 + ), }, }, references: {}, diff --git a/services/history-v1/app.js b/services/history-v1/app.js index 6b3a2ba8f8..2ad490fb6b 100644 --- a/services/history-v1/app.js +++ b/services/history-v1/app.js @@ -5,6 +5,7 @@ // Metrics must be initialized before importing anything else require('@overleaf/metrics/initialize') +const config = require('config') const Events = require('events') const BPromise = require('bluebird') const express = require('express') @@ -47,9 +48,9 @@ app.use(cors()) security.setupSSL(app) security.setupBasicHttpAuthForSwaggerDocs(app) +const HTTP_REQUEST_TIMEOUT = parseInt(config.get('httpRequestTimeout'), 10) app.use(function (req, res, next) { - // use a 5 minute timeout on all responses - res.setTimeout(5 * 60 * 1000) + res.setTimeout(HTTP_REQUEST_TIMEOUT) next() }) diff --git a/services/history-v1/config/custom-environment-variables.json b/services/history-v1/config/custom-environment-variables.json index 05ec2907c7..1822d33aa4 100644 --- a/services/history-v1/config/custom-environment-variables.json +++ b/services/history-v1/config/custom-environment-variables.json @@ -56,5 +56,6 @@ }, "clusterWorkers": "CLUSTER_WORKERS", "maxFileUploadSize": "MAX_FILE_UPLOAD_SIZE", - "httpsOnly": "HTTPS_ONLY" + "httpsOnly": "HTTPS_ONLY", + "httpRequestTimeout": "HTTP_REQUEST_TIMEOUT" } diff --git a/services/history-v1/config/default.json b/services/history-v1/config/default.json index ff15214f90..84fd220789 100644 --- a/services/history-v1/config/default.json +++ b/services/history-v1/config/default.json @@ -25,5 +25,6 @@ "maxFileUploadSize": "52428800", "databasePoolMin": "2", "databasePoolMax": "10", - "httpsOnly": "false" + "httpsOnly": "false", + "httpRequestTimeout": "300000" } diff --git a/services/project-history/app/js/HistoryStoreManager.js b/services/project-history/app/js/HistoryStoreManager.js index 42bbe0c4a2..a2c8f44539 100644 --- a/services/project-history/app/js/HistoryStoreManager.js +++ b/services/project-history/app/js/HistoryStoreManager.js @@ -17,7 +17,7 @@ import * as Errors from './Errors.js' import * as LocalFileWriter from './LocalFileWriter.js' import * as HashManager from './HashManager.js' -const HTTP_REQUEST_TIMEOUT = 300 * 1000 // 5 minutes +const HTTP_REQUEST_TIMEOUT = Settings.apis.history_v1.requestTimeout /** * Container for functions that need to be mocked in tests diff --git a/services/project-history/config/settings.defaults.cjs b/services/project-history/config/settings.defaults.cjs index b0ea5feec0..fa2cd9c694 100644 --- a/services/project-history/config/settings.defaults.cjs +++ b/services/project-history/config/settings.defaults.cjs @@ -20,6 +20,9 @@ module.exports = { filestore: { url: `http://${process.env.FILESTORE_HOST || 'localhost'}:3009`, }, + history_v1: { + requestTimeout: parseInt(process.env.V1_REQUEST_TIMEOUT || '300000', 10), + }, web: { url: `http://${ process.env.WEB_API_HOST || process.env.WEB_HOST || 'localhost' diff --git a/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js b/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js index ccd85bb4db..5d25164ff2 100644 --- a/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js +++ b/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js @@ -23,6 +23,7 @@ describe('HistoryStoreManager', function () { filestore: { url: 'http://filestore.sharelatex.production', }, + history_v1: { requestTimeout: 123 }, }, } this.latestChunkRequestArgs = sinon.match({