Skip to content

fix: clamp setTimeout delays to avoid TimeoutOverflowWarning#3

Open
msallin wants to merge 1 commit intotkurki:masterfrom
msallin:claude/festive-engelbart
Open

fix: clamp setTimeout delays to avoid TimeoutOverflowWarning#3
msallin wants to merge 1 commit intotkurki:masterfrom
msallin:claude/festive-engelbart

Conversation

@msallin
Copy link
Copy Markdown

@msallin msallin commented Apr 5, 2026

Summary

Fixes a TimeoutOverflowWarning surfaced in signalk-server logs (which depends on dnssd2):

```
(node:18444) TimeoutOverflowWarning: 146811648000 does not fit into a 32-bit signed integer. Timeout duration was set to 1.
at TimerContainer.set (.../dnssd2/lib/TimerContainer.js:97:26)
at ExpiringRecordCollection._schedule (.../dnssd2/lib/ExpiringRecordCollection.js:398:33)
at ExpiringRecordCollection.add (.../dnssd2/lib/ExpiringRecordCollection.js:100:12)
at NetworkInterface._onMessage (.../dnssd2/lib/NetworkInterface.js:304:10)
```

Root cause

ExpiringRecordCollection._schedule calls setTimeout with record.ttl * 1000. If an mDNS packet arrives with a TTL larger than ~24.8 days (0x7fffffff ms), Node emits TimeoutOverflowWarning and silently coerces the delay to 1ms — so the record expires immediately instead of at its real TTL. In the observed case the TTL was ~146,811,648 seconds (~4.6 years), likely from a malformed/rogue announcement on the network.

Side effects:

  • Cache entry evicted instantly instead of honoring its TTL.
  • Warning pollutes host application logs.

Fix

Clamp delays in TimerContainer.set / setLazy to 0x7fffffff so oversized values never reach setTimeout raw. The timer still fires — just capped at the 24.8-day ceiling.

Changes applied to both src/ (source) and lib/ (babel build) to keep them in sync.

Test plan

  • npm test
  • Verify no TimeoutOverflowWarning in signalk-server logs after upgrading

🤖 Generated with Claude Code

setTimeout delays are clamped to a 32-bit signed integer by Node.js.
Values larger than 0x7fffffff trigger a TimeoutOverflowWarning and are
silently coerced to 1ms, causing timers to fire immediately. When an
mDNS record arrives with an oversized TTL, this caused cache entries
to be evicted instantly and spammed host application logs with the
warning.

Clamp delays in TimerContainer.set/setLazy so oversized TTLs cap at
the 24.8-day maximum instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant