Problem
backoff.util.ts has two issues:
-
withTimeout() missing input validation — Unlike its sibling raceWithTimeout() in timeout.util.ts, withTimeout() does not validate its timeoutMs parameter. When called with NaN, Infinity, or negative values, setTimeout clamps the delay to ~1ms (per Node.js behavior), causing the promise to reject immediately regardless of the actual work. This is inconsistent with raceWithTimeout() which explicitly throws a RangeError for invalid values.
-
Dead sleepWithAbort() export — The sleepWithAbort() function is exported but never imported or used anywhere in the codebase. It is dead code.
Root Cause
withTimeout() was implemented without the input validation that was added to raceWithTimeout().
sleepWithAbort() was likely added for future use but was never integrated, leaving dead code in the module.
Proposed Fix
- Add input validation to
withTimeout() matching raceWithTimeout() behavior: reject non-finite or negative timeoutMs values with a RangeError.
- Remove the dead
sleepWithAbort() function.
Impact
- Severity: Low —
withTimeout() callers currently use hardcoded valid values, so the validation is defensive. Dead code removal is a cleanup.
- Affected scenarios: Any future caller passing invalid timeout values to
withTimeout() would get a clear RangeError instead of silent misbehavior.
Problem
backoff.util.tshas two issues:withTimeout()missing input validation — Unlike its siblingraceWithTimeout()intimeout.util.ts,withTimeout()does not validate itstimeoutMsparameter. When called withNaN,Infinity, or negative values,setTimeoutclamps the delay to ~1ms (per Node.js behavior), causing the promise to reject immediately regardless of the actual work. This is inconsistent withraceWithTimeout()which explicitly throws aRangeErrorfor invalid values.Dead
sleepWithAbort()export — ThesleepWithAbort()function is exported but never imported or used anywhere in the codebase. It is dead code.Root Cause
withTimeout()was implemented without the input validation that was added toraceWithTimeout().sleepWithAbort()was likely added for future use but was never integrated, leaving dead code in the module.Proposed Fix
withTimeout()matchingraceWithTimeout()behavior: reject non-finite or negativetimeoutMsvalues with aRangeError.sleepWithAbort()function.Impact
withTimeout()callers currently use hardcoded valid values, so the validation is defensive. Dead code removal is a cleanup.withTimeout()would get a clearRangeErrorinstead of silent misbehavior.