fix(core): clamp large timer delays to TIMEOUT_MAX instead of 1ms#32860
Open
bartlomieju wants to merge 1 commit intodenoland:mainfrom
Open
fix(core): clamp large timer delays to TIMEOUT_MAX instead of 1ms#32860bartlomieju wants to merge 1 commit intodenoland:mainfrom
bartlomieju wants to merge 1 commit intodenoland:mainfrom
Conversation
`AbortSignal.timeout(2 ** 53 - 1)` was aborting instantly because values above TIMEOUT_MAX (2^31-1) were clamped to 1ms. Now they clamp to TIMEOUT_MAX (~24.8 days) instead. Closes denoland#32858 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
Worth noting that this diverges from Node.js behavior: Node.js clamps values above // Node.js (lib/internal/timers.js):
// setTimeout(fn, 2**32) → fires after 1ms + warning
// Deno (this PR):
// setTimeout(fn, 2**32) → fires after ~24.8 daysThe Deno behavior is arguably more intuitive (a huge timeout stays huge rather than becoming instant), but it's a conscious compat difference. Might be worth a brief comment in the code noting this is intentional. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AbortSignal.timeout(2 ** 53 - 1)was aborting instantly becausethe JS timer clamping logic treated values above
TIMEOUT_MAX(2^31-1)the same as values below 1 — both got set to 1ms.
Fix: clamp values above
TIMEOUT_MAXtoTIMEOUT_MAX(~24.8 days)instead of 1ms. Values below 1 (NaN, negative, zero) still clamp to 1ms.
Regression from #32543 (timer refactor moving processing from Rust to JS).
Closes #32858
Test plan
./x test-unit timerspassesAbortSignal.timeout(2**53-1)no longer aborts instantly🤖 Generated with Claude Code