Repository navigation
poll_oneoff: do not sleep when there is no clock subscription - #2540
Merged
evacchi merged 2 commits intoSep 8, 2026
Merged
Conversation
The timeout is initialized to the max Duration so the loop can take the minimum across clock subscriptions. With no clock subscription that sentinel survives, and the early return path sleeps on it, so a guest calling poll(fds, nfds, -1) gets its events written back and then the host sleeps for 9223372036854775807ns. wasi-libc only emits a clock subscription when the timeout is non-negative, and `wazero run` configures a real Nanosleep. Only observe the timeout when a clock subscription set it. Signed-off-by: Iain <[email protected]>
evacchi
reviewed
Sep 7, 2026
evacchi
left a comment
Member
There was a problem hiding this comment.
I think you might simplify to something like
const noTimeout = time.Duration(1<<63 - 1)
...
timeout := noTimeout
...
if timeout != noTimeout {
sysCtx.Nanosleep(int64(timeout))
}
Signed-off-by: Iain <[email protected]>
Contributor
Author
|
Cheers @evacchi, done. I'd reached for a flag beacuse I was tracking "was there a clock sub" rather than "is the timeout still the sentinel". I kept the One edge worth naming: a clock sub asking for exactly |
evacchi
approved these changes
Sep 8, 2026
samyfodil
added a commit
to samyfodil/wazy
that referenced
this pull request
Oct 18, 2026
wasi-libc's poll(fds, n, -1) emits no clock subscription, so the timeout kept its max-duration sentinel and poll_oneoff slept on it forever once every event was already written. Only sleep when a clock lowered it. Port of wazero/wazero#2540. Also adds wazero#2507's fd_renumber onto stdio cases, which wazy already allows.
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.
wazero runnever comes back from a guest that callspoll(fds, nfds, -1)on a writable fd. The events do get written back and nevents is right. Then it parks inNanosleepfor 9223372036854775807ns, which is about 292 years.timeoutstarts at max Duration so the loop can take the minimum, and only a clock subscription ever lowers it. wasi-libc adds that subscription insideif (timeout)(ppoll.c), so a poll with an infinite timeout sends a list with no clock event in it, and the sentinel makes it all the way to the sleep.The comment above that sleep already says the timeout is nonzero if there are clock subscriptions, so this is mostly just making that true.
The test passes its own
Nanosleepin beacuse the default one is a no-op. Nothing in the suite ever saw the argument.Somthing adjacent I've left alone: with a clock subscription and an fd_write subscription together, the fd_write event gets acked straight away but the whole clock timeout still gets slept. Could well be deliberate, and I didnt want to change it in here.