Repository navigation
wasm: round sleepTicks up to a whole millisecond - #5818
Open
joeblew999 wants to merge 1 commit into
Open
joeblew999 wants to merge 1 commit into
joeblew999 wants to merge 1 commit into
Conversation
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 tinygo-org#5798
Contributor
|
Is this solving an issue with TinyGo or cloudflare workers? It kind of sounds like the latter. This also sounds like it could break users who depended on the current behaviour? |
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.
Fixes #5798.
The problem. On Cloudflare Workers (production, not local workerd) the clock only advances by a timer's delay rounded down to a whole millisecond.
sleepTickspasses a fractional delay tosetTimeout, so when less than a millisecond is left the scheduler re-arms a timer that never moves the clock, and Go timers (time.Sleep,time.Timer, context deadlines) stall until some other I/O happens.The change. One line in
targets/wasm_exec.js:Math.ceilon the delay. A sleep can end up to a millisecond late, whichsetTimeoutnever promised to beat anyway.Measured. An HTTP API on Cloudflare Workers, built with this branch's base (dev), 24 streams each asked to end after a 2 s Go timer:
One caveat on that table: the program runs on workers-go, which ships its own copy of
wasm_exec.js(it adds a context argument torun), so the rounding was applied to that copy, with dev's compiler and runtime. This PR's file itself was run under Node with a program oftime.Sleep(1.5 ms and 250 ms), atime.Timer(100.3 ms), a context deadline (50 ms) and ten 10 ms ticks: 513 ms in all, against 510 ms before the change and 502 ms asked for.