Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): accept a fractional net.fetch timeout

Yudhi Armyndharisd368552fb119
diff --git a/src/core/plugins/plugin-net.spec.ts b/src/core/plugins/plugin-net.spec.ts
index da396425b..51faeac2a 100644
--- a/src/core/plugins/plugin-net.spec.ts
+++ b/src/core/plugins/plugin-net.spec.ts
@@ -88,6 +88,14 @@ describe('performPluginFetch', () => {
expect(sink.init?.signal).toBeInstanceOf(AbortSignal);
});
+ it.each([1.5, 0.4, 2500.9])('accepts a fractional timeoutMs of %s', async timeoutMs => {
+ // AbortSignal.timeout throws ERR_OUT_OF_RANGE for a non-integer, which failed the plugin's request.
+ const fetcher = fakeSafeFetch(cannedResponse('{}', {}), {});
+ await expect(
+ performPluginFetch('https://api.example.com/t', { timeoutMs }, { fetch: fetcher }),
+ ).resolves.toMatchObject({ ok: true });
+ });
+
it('rejects a response whose declared content-length exceeds the cap', async () => {
const sink: { init?: RequestInit } = {};
const big = String(11 * 1024 * 1024);
diff --git a/src/core/plugins/plugin-net.ts b/src/core/plugins/plugin-net.ts
index 585c76a86..852d1695a 100644
--- a/src/core/plugins/plugin-net.ts
+++ b/src/core/plugins/plugin-net.ts
@@ -110,7 +110,8 @@ export async function performPluginFetch(
// throws a RangeError, silently defeating the documented default + hard-cap clamp.
const requested =
typeof opts.timeoutMs === 'number' && Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : DEFAULT_TIMEOUT_MS;
- const timeoutMs = Math.min(Math.max(requested, 1), MAX_TIMEOUT_MS);
+ // AbortSignal.timeout only takes an integer, so a fractional value is cut to one before the clamp.
+ const timeoutMs = Math.min(Math.max(Math.trunc(requested), 1), MAX_TIMEOUT_MS);
// Reject-when-full BEFORE reserving a slot, so total concurrent host-side buffering stays bounded to
// MAX_INFLIGHT_FETCHES × MAX_BODY_BYTES. Check + increment are synchronous (single event-loop turn),
// so no interleaving can overshoot the cap; the slot is released in the finally below.