Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): validate WEBHOOK_SHUTDOWN_DRAIN_MS at boot

Yudhi Armyndharisbc7d8270c384
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2835ddd7d..850003204 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -147,6 +147,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `docker-compose.dev.yml` now waits up to 75 s on a stuck stop instead of Docker's 10 s default.
- Queue workers now stop taking jobs when shutdown begins and wait at most 10 s for running ones, so a queued webhook or plugin ingress job still running then is re-run after the next start; receivers must deduplicate on `X-OpenWA-Idempotency-Key`.
- Boot fails on a `PORT` with surrounding whitespace or a whitespace-only `PORT`; remove the padding.
+- Boot fails on a `WEBHOOK_SHUTDOWN_DRAIN_MS` that is not a non-negative integer (for example `30s`) instead of silently using 5000.
- Aged undispatched ingress events are dead-lettered instead of deleted; some may already have been delivered, so check before redriving them.
- Java SDK (next SDK release after 0.5.1): the request timeout (default 30 s) also bounds the response body; raise it for large media downloads.
- With `OPENWA_DATA_DIR` set, `backup.sh` and `restore.sh` read the default SQLite databases and `./data/...` paths in `./.env` under it; pass a path in the environment to keep it in the working directory.
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.ts
index e49790da7..a90ca2011 100644
--- a/src/config/env.validation.spec.ts
+++ b/src/config/env.validation.spec.ts
@@ -687,6 +687,18 @@ describe('validateEnv', () => {
expect(() => validateEnv({ SHUTDOWN_DELAY_MS: '0' })).not.toThrow();
});
+ it('rejects a malformed WEBHOOK_SHUTDOWN_DRAIN_MS but keeps 0 (no wait), like the other shutdown knobs', () => {
+ // A malformed value was silently replaced by 5000, which also sets the force-exit budget, so a typo
+ // such as `30s` quietly cut the drain the operator asked for.
+ for (const bad of ['30s', '-5', 'abc', '1.5']) {
+ expect(() => validateEnv({ WEBHOOK_SHUTDOWN_DRAIN_MS: bad })).toThrow(
+ /WEBHOOK_SHUTDOWN_DRAIN_MS must be a non-negative integer/,
+ );
+ }
+ expect(() => validateEnv({ WEBHOOK_SHUTDOWN_DRAIN_MS: '0' })).not.toThrow();
+ expect(() => validateEnv({ WEBHOOK_SHUTDOWN_DRAIN_MS: '12000' })).not.toThrow();
+ });
+
it.each([
'WEBHOOK_FAILURE_RETENTION_DAYS',
'WEBHOOK_OUTBOX_RETENTION_DAYS',
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 2106329f1..e7ac04b28 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -246,6 +246,7 @@ export function validateEnv(config: EnvConfig): EnvConfig {
'REDIS_CACHE_DB',
'INBOUND_MEDIA_GLOBAL_CONCURRENCY', // 0 = no process-wide ceiling, only the per-session one
'SHUTDOWN_DELAY_MS', // 0 = no drain; parseInt read `3s` as a 3 ms drain
+ 'WEBHOOK_SHUTDOWN_DRAIN_MS', // 0 = no wait; a malformed value fell back to 5000 and also moved the force-exit
// 0 = disabled. A negative value failed the digits-only read and silently kept the default sweep.
'MESSAGE_REAPER_INTERVAL_MS',
'WEBHOOK_RECONCILE_INTERVAL_MS',