Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): validate the storage export and sweep interval knobs

Yudhi Armyndharisa4e750b7cca0
diff --git a/.env.example b/.env.example
index 71f7a17b0..9fb4b9368 100644
--- a/.env.example
+++ b/.env.example
@@ -599,17 +599,21 @@ WEBHOOK_SSRF_PROTECT=true
# Storage import/export limits (ADMIN /infra/storage/* endpoints):
# STORAGE_IMPORT_MAX_BYTES=209715200 # per-entry cap for a tar.gz import; aborts on overflow (default 200 MiB)
# STORAGE_IMPORT_MAX_ENTRIES=100000 # max entries in an import archive; aborts beyond this (default 100000)
+# The two STORAGE_EXPORT_* values are raw milliseconds: a value that is not a positive integer
+# (`1h` included) fails the boot, and so does a TTL above 2147483647 ms (Node's timer ceiling).
# STORAGE_EXPORT_TTL_MS=3600000 # auto-delete an export archive after this long (default 1h)
+# STORAGE_EXPORT_SWEEP_MAX_AGE_MS=86400000 # boot sweep deletes export archives orphaned by a restart, older than this (default 24h)
# How often an S3-configured service re-probes a bucket that was unreachable at boot (media storage is
# degraded to the local fallback dir until it recovers; writes return to S3 automatically). Unset
# takes the default; a value that is not a positive integer, or above 2147483647 ms (Node's timer
# ceiling), fails the boot.
# S3_REPROBE_INTERVAL_MS=60000 # default 60s
-# STORAGE_EXPORT_SWEEP_MAX_AGE_MS=86400000 # boot sweep deletes export archives orphaned by a restart, older than this (default 24h)
# Outbound rows stuck PENDING (process died between the pre-send save and the final save) are marked
# FAILED with a `reapedAt` metadata marker by a periodic reaper, which also re-emits
# `message:persisted` so hook-driven search providers reconcile. Set the interval to 0 to disable
-# the reaper; a blank or unparseable value falls back to the default instead of disabling it.
+# the reaper; a blank or unparseable value falls back to the default instead of disabling it, and a
+# value above 2147483647 ms (Node's timer ceiling) fails the boot. The same ceiling applies to the
+# INGRESS_ and WEBHOOK_RECONCILE_INTERVAL_MS knobs below.
# MESSAGE_REAPER_INTERVAL_MS=600000 # how often the reaper sweeps (default 10min)
# MESSAGE_REAPER_GRACE_MS=3600000 # only rows older than this are reaped (default 1h)
# MESSAGE_REAPER_BATCH_SIZE=50 # max rows reaped per sweep (default 50)
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.ts
index 7b68a8d43..ac0d0ac58 100644
--- a/src/config/env.validation.spec.ts
+++ b/src/config/env.validation.spec.ts
@@ -533,6 +533,8 @@ describe('validateEnv', () => {
'STATUS_ORPHAN_SWEEP_INTERVAL_MS',
'STATUS_ORPHAN_GRACE_MS',
'S3_REPROBE_INTERVAL_MS',
+ 'STORAGE_EXPORT_TTL_MS',
+ 'STORAGE_EXPORT_SWEEP_MAX_AGE_MS',
])('rejects a unit-suffixed or non-positive %s and accepts a plain count', key => {
expect(() => validateEnv({ [key]: '1h' })).toThrow(new RegExp(`${key} must be a positive integer`));
expect(() => validateEnv({ [key]: '0' })).toThrow(new RegExp(`${key} must be a positive integer`));
@@ -550,6 +552,10 @@ describe('validateEnv', () => {
'CHAT_MEDIA_ORPHAN_SWEEP_INTERVAL_MS',
'STATUS_ORPHAN_SWEEP_INTERVAL_MS',
'S3_REPROBE_INTERVAL_MS',
+ 'STORAGE_EXPORT_TTL_MS',
+ 'MESSAGE_REAPER_INTERVAL_MS',
+ 'WEBHOOK_RECONCILE_INTERVAL_MS',
+ 'INGRESS_RECONCILE_INTERVAL_MS',
])('rejects a %s above the Node timer ceiling', key => {
expect(() => validateEnv({ [key]: '2147483648' })).toThrow(new RegExp(`${key} must not exceed 2147483647 ms`));
expect(() => validateEnv({ [key]: '2147483647' })).not.toThrow();
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 79c3c95f5..7deab92e2 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -333,6 +333,10 @@ export function validateEnv(config: EnvConfig): EnvConfig {
'STATUS_ORPHAN_SWEEP_INTERVAL_MS',
'STATUS_ORPHAN_GRACE_MS',
'S3_REPROBE_INTERVAL_MS',
+ // Same parseInt read: `1h` deleted a fresh export archive after 1 ms, and a `24h` sweep age made
+ // the boot sweep delete every archive older than 24 ms, breaking export, restart, import.
+ 'STORAGE_EXPORT_TTL_MS',
+ 'STORAGE_EXPORT_SWEEP_MAX_AGE_MS',
]) {
checkPositiveInt(key);
}
@@ -347,6 +351,11 @@ export function validateEnv(config: EnvConfig): EnvConfig {
['CHAT_MEDIA_ORPHAN_SWEEP_INTERVAL_MS', 'the orphan sweep reruns every millisecond'],
['STATUS_ORPHAN_SWEEP_INTERVAL_MS', 'the orphan sweep reruns every millisecond'],
['S3_REPROBE_INTERVAL_MS', 'S3 is re-probed every millisecond while it is down'],
+ ['STORAGE_EXPORT_TTL_MS', 'the export archive is deleted about 1 ms after it is written'],
+ // 0 still disables these three, so they carry only the ceiling, not the positive-only check.
+ ['MESSAGE_REAPER_INTERVAL_MS', 'the pending message reaper reruns every millisecond'],
+ ['WEBHOOK_RECONCILE_INTERVAL_MS', 'the webhook reconciler reruns every millisecond'],
+ ['INGRESS_RECONCILE_INTERVAL_MS', 'the ingress reconciler reruns every millisecond'],
]) {
const raw = str(key);
const n = raw !== undefined && DECIMAL_INTEGER.test(raw) ? Number(raw) : NaN;