From 0104707490d343396ac6fc806988e7881e564f39 Mon Sep 17 00:00:00 2001 From: joeblew999 Date: Fri, 2 Oct 2026 19:49:11 +0700 Subject: [PATCH] wasm: round sleepTicks up to a whole millisecond On Cloudflare Workers the clock only advances by a timer's delay rounded down to a whole millisecond. sleepTicks passed a fractional delay to setTimeout, so when less than a millisecond was left the scheduler re-armed a timer that never moved the clock, and Go timers (time.Sleep, time.Timer, context deadlines) stalled until some other I/O happened. Fixes #5798 --- targets/wasm_exec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js index fd4c8a04d4..845456aa14 100644 --- a/targets/wasm_exec.js +++ b/targets/wasm_exec.js @@ -272,7 +272,11 @@ "runtime.sleepTicks": (timeout) => { // Do not sleep, only reactivate the scheduler after the given // timeout, keeping exactly one pending wakeup. - const ms = Number(timeout) / 1e6; + // Round up to a whole millisecond. Some hosts (Cloudflare + // Workers) only advance the clock by a timer's delay rounded + // down to a millisecond, so a fractional remainder would be + // slept again and again without the clock ever moving. + const ms = Math.ceil(Number(timeout) / 1e6); const due = Date.now() + ms; if (this._scheduledWakeup !== undefined) { if (this._scheduledWakeupDue <= due) return;