Repository navigation
fix: accept Node.js Timeout objects as the Delay timer handle - #1095
Open
PedroRosalba wants to merge 1 commit into
Open
PedroRosalba wants to merge 1 commit into
PedroRosalba wants to merge 1 commit into
Conversation
From compatibility date 2026-08-04 `nodejs_compat` is on by default, which
implies `enable_nodejs_global_timers`: `setTimeout` returns a Node.js
`Timeout` object instead of a number. `Delay` bound it through web-sys as
`Result<i32, JsValue>` and unwrapped, and the type-checked glue of
`worker-build --dev` rejected the object ("expected a number argument,
found object"), so every `Delay` panicked in dev builds. Release glue
coerced the object to its id, which is why only dev builds were affected.
Bind `setTimeout`/`clearTimeout` directly with an opaque `JsValue` handle
and hand the same handle back on drop, which works for both handle kinds.
Add a `delay.spec.ts` that runs the test worker on a second Miniflare
instance at compatibility date 2026-08-04 next to the default one, with a
drop-path route that races two delays.
Fixes cloudflare#1086
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.
Problem
From compatibility date 2026-08-04,
nodejs_compatis on by default and impliesenable_nodejs_global_timers, sosetTimeoutreturns a Node.jsTimeoutobject instead of a number.Delaybound it through web-sys asResult<i32, JsValue>and unwrapped it. The type-checked glue ofworker-build --devrejects the object (expected a number argument, found object), so everyDelaypanicked in dev builds; release glue coerces the object to its id, which is why only dev builds were affected.Fix
Bind
setTimeout/clearTimeoutdirectly with an opaqueJsValuehandle and hand the same handle back on drop. This works for both the numeric and theTimeouthandle, and on both compatibility date ranges.Tests
Adds
delay.spec.ts, which boots the test worker on a second Miniflare instance at compatibility date 2026-08-04 next to the default one, plus a drop-path route that races two delays. Fails onmainunder--dev, passes with this change.Tested on macOS (Apple Silicon) only.
Fixes #1086