Skip to content

Commit 89f0f01

Browse files
committed
fix(submit-timeout): Allow to configure HTTP POST timeout for submit and message upload API endpoints (previous default 10s)
1 parent 00e210a commit 89f0f01

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/consts.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ module.exports = {
102102
DEFAULT_PAGE_SIZE: 20,
103103

104104
// Max POST payload size for message upload requests. NB! Does not apply for all routes
105-
DEFAULT_MAX_BODY_SIZE: 50 * 1024 * 1024,
105+
DEFAULT_MAX_BODY_SIZE: 50 * 1024 * 1024, // B
106+
107+
// Payload reception timeout in milliseconds for message uploads
108+
// https://hapi.dev/api/?v=21.3.3#-routeoptionspayloadtimeout
109+
DEFAULT_MAX_PAYLOAD_TIMEOUT: 10 * 1000, // s
106110

107111
DEFAULT_EENGINE_TIMEOUT: 10 * 1000,
108112
DEFAULT_MAX_ATTACHMENT_SIZE: 5 * 1024 * 1024,

lib/routes-ui.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const {
7171
FETCH_TIMEOUT,
7272
DEFAULT_DELIVERY_ATTEMPTS,
7373
DEFAULT_MAX_BODY_SIZE,
74+
DEFAULT_MAX_PAYLOAD_TIMEOUT,
7475
MAX_FORM_TTL,
7576
NONCE_BYTES,
7677
ALLOWED_REDIS_LATENCY
@@ -83,6 +84,7 @@ config.api = config.api || {
8384
};
8485

8586
const MAX_BODY_SIZE = getByteSize(readEnvValue('EENGINE_MAX_BODY_SIZE') || config.api.maxBodySize) || DEFAULT_MAX_BODY_SIZE;
87+
const MAX_PAYLOAD_TIMEOUT = getByteSize(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT;
8688

8789
const { fetch: fetchCmd, Agent } = require('undici');
8890
const fetchAgent = new Agent({ connect: { timeout: FETCH_TIMEOUT } });
@@ -1663,7 +1665,8 @@ return true;`
16631665
},
16641666
options: {
16651667
payload: {
1666-
maxBytes: MAX_BODY_SIZE
1668+
maxBytes: MAX_BODY_SIZE,
1669+
timeout: MAX_PAYLOAD_TIMEOUT
16671670
},
16681671
validate: {
16691672
options: {

workers/api.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const {
117117
LIST_UNSUBSCRIBE_NOTIFY,
118118
FETCH_TIMEOUT,
119119
DEFAULT_MAX_BODY_SIZE,
120+
DEFAULT_MAX_PAYLOAD_TIMEOUT,
120121
DEFAULT_EENGINE_TIMEOUT,
121122
DEFAULT_MAX_ATTACHMENT_SIZE,
122123
MAX_FORM_TTL,
@@ -202,6 +203,9 @@ const IMAP_WORKER_COUNT = getWorkerCount(readEnvValue('EENGINE_WORKERS') || (con
202203
// NB! the default for other requests is 1MB
203204
const MAX_BODY_SIZE = getByteSize(readEnvValue('EENGINE_MAX_BODY_SIZE') || config.api.maxBodySize) || DEFAULT_MAX_BODY_SIZE;
204205

206+
// Payload reception timeout in milliseconds for message upload requests
207+
const MAX_PAYLOAD_TIMEOUT = getByteSize(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT;
208+
205209
// CORS configuration for API requests
206210
// By default, CORS is not enabled
207211
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
35813585
},
35823586
options: {
35833587
payload: {
3584-
maxBytes: MAX_BODY_SIZE
3588+
maxBytes: MAX_BODY_SIZE,
3589+
timeout: MAX_PAYLOAD_TIMEOUT
35853590
},
35863591

35873592
description: 'Upload message',
@@ -4627,7 +4632,8 @@ When making API calls remember that requests against the same account are queued
46274632
},
46284633
options: {
46294634
payload: {
4630-
maxBytes: MAX_BODY_SIZE
4635+
maxBytes: MAX_BODY_SIZE,
4636+
timeout: MAX_PAYLOAD_TIMEOUT
46314637
},
46324638

46334639
description: 'Submit message for delivery',

0 commit comments

Comments
 (0)