From 89f0f013fe3c0d0028e7832d3d54a62d363251b3 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Fri, 2 Feb 2024 09:25:36 +0200 Subject: [PATCH] fix(submit-timeout): Allow to configure HTTP POST timeout for submit and message upload API endpoints (previous default 10s) --- lib/consts.js | 6 +++++- lib/routes-ui.js | 5 ++++- workers/api.js | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/consts.js b/lib/consts.js index 7d29ea8a..0af5ed81 100644 --- a/lib/consts.js +++ b/lib/consts.js @@ -102,7 +102,11 @@ module.exports = { DEFAULT_PAGE_SIZE: 20, // Max POST payload size for message upload requests. NB! Does not apply for all routes - DEFAULT_MAX_BODY_SIZE: 50 * 1024 * 1024, + DEFAULT_MAX_BODY_SIZE: 50 * 1024 * 1024, // B + + // Payload reception timeout in milliseconds for message uploads + // https://hapi.dev/api/?v=21.3.3#-routeoptionspayloadtimeout + DEFAULT_MAX_PAYLOAD_TIMEOUT: 10 * 1000, // s DEFAULT_EENGINE_TIMEOUT: 10 * 1000, DEFAULT_MAX_ATTACHMENT_SIZE: 5 * 1024 * 1024, diff --git a/lib/routes-ui.js b/lib/routes-ui.js index 3a309d66..8f73b5b0 100644 --- a/lib/routes-ui.js +++ b/lib/routes-ui.js @@ -71,6 +71,7 @@ const { FETCH_TIMEOUT, DEFAULT_DELIVERY_ATTEMPTS, DEFAULT_MAX_BODY_SIZE, + DEFAULT_MAX_PAYLOAD_TIMEOUT, MAX_FORM_TTL, NONCE_BYTES, ALLOWED_REDIS_LATENCY @@ -83,6 +84,7 @@ config.api = config.api || { }; const MAX_BODY_SIZE = getByteSize(readEnvValue('EENGINE_MAX_BODY_SIZE') || config.api.maxBodySize) || DEFAULT_MAX_BODY_SIZE; +const MAX_PAYLOAD_TIMEOUT = getByteSize(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT; const { fetch: fetchCmd, Agent } = require('undici'); const fetchAgent = new Agent({ connect: { timeout: FETCH_TIMEOUT } }); @@ -1663,7 +1665,8 @@ return true;` }, options: { payload: { - maxBytes: MAX_BODY_SIZE + maxBytes: MAX_BODY_SIZE, + timeout: MAX_PAYLOAD_TIMEOUT }, validate: { options: { diff --git a/workers/api.js b/workers/api.js index b5d35ae6..0efbf95c 100644 --- a/workers/api.js +++ b/workers/api.js @@ -117,6 +117,7 @@ const { LIST_UNSUBSCRIBE_NOTIFY, FETCH_TIMEOUT, DEFAULT_MAX_BODY_SIZE, + DEFAULT_MAX_PAYLOAD_TIMEOUT, DEFAULT_EENGINE_TIMEOUT, DEFAULT_MAX_ATTACHMENT_SIZE, MAX_FORM_TTL, @@ -202,6 +203,9 @@ const IMAP_WORKER_COUNT = getWorkerCount(readEnvValue('EENGINE_WORKERS') || (con // NB! the default for other requests is 1MB const MAX_BODY_SIZE = getByteSize(readEnvValue('EENGINE_MAX_BODY_SIZE') || config.api.maxBodySize) || DEFAULT_MAX_BODY_SIZE; +// Payload reception timeout in milliseconds for message upload requests +const MAX_PAYLOAD_TIMEOUT = getByteSize(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT; + // CORS configuration for API requests // By default, CORS is not enabled const CORS_ORIGINS = readEnvValue('EENGINE_CORS_ORIGIN') || (config.cors && config.cors.origin); @@ -3581,7 +3585,8 @@ When making API calls remember that requests against the same account are queued }, options: { payload: { - maxBytes: MAX_BODY_SIZE + maxBytes: MAX_BODY_SIZE, + timeout: MAX_PAYLOAD_TIMEOUT }, description: 'Upload message', @@ -4627,7 +4632,8 @@ When making API calls remember that requests against the same account are queued }, options: { payload: { - maxBytes: MAX_BODY_SIZE + maxBytes: MAX_BODY_SIZE, + timeout: MAX_PAYLOAD_TIMEOUT }, description: 'Submit message for delivery',