Skip to content

Commit

Permalink
fix(submit-timeout): Allow to configure HTTP POST timeout for submit …
Browse files Browse the repository at this point in the history
…and message upload API endpoints (previous default 10s)
  • Loading branch information
andris9 committed Feb 2, 2024
1 parent 00e210a commit 89f0f01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 } });
Expand Down Expand Up @@ -1663,7 +1665,8 @@ return true;`
},
options: {
payload: {
maxBytes: MAX_BODY_SIZE
maxBytes: MAX_BODY_SIZE,
timeout: MAX_PAYLOAD_TIMEOUT
},
validate: {
options: {
Expand Down
10 changes: 8 additions & 2 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 89f0f01

Please sign in to comment.