want to bring more visibility to https://github.com/bytecodealliance/wasmtime/issues/9667#issuecomment-2608134946: Alex pointed out that, basically, the guarantees I wrote down for input-stream read readiness are bogus and cant reasonably be met on top of posix. They've never been met by wasmtime, so I think we should just change the spec to weaken the guarantees provided, and accommodate that in e.g. wstd and any other places we depended on it.
@Guy Bedford do you know if jco has the same behavior as wasmtime here?
(cc @Dan Gohman @Yosh Wuyts @Joel Dice )
I'm pretty sure Node.js stream reads after poll can return zero bytes in reality as well, so this wouldn't be a problem for JS if it's already happening there too
@Pat Hickey I read over the issue - what's the proposed mapping back to Rust from this? Is it something like:
StreamError::Closed
-> AsyncRead::read
: Ok(0)
Ok(0)
-> AsyncRead::read
: [pending future]Heh, okay what I wrote is less clear than I imagined it would be. I guess I'm wondering what the concrete change we're proposing here is?
I presume slightly changing the documentation from
The pollable given by
subscribe
will be ready when more bytes are available.
to something along the lines of:
The pollable given by
subscribe
will be ready when the read should be attempted again.
ohhh, I see - and that gives us room to schedule a wake to signal EOF, right?
Hmm, not sure what you mean, but I don't think EOF has anything to do with this
More about EWOULDBLOCK (a.k.a. Poll:Pending in rust)
Oh interesting; I meant EOF as "end of stream" - so like, we can signal "ready" to say "there are no more bytes here". The previous wording read like that was disallowed?
ahhh, okay - that's also interesting
either way tho: I now understand that the current wording is too narrow, ty!
Basically we want to communicate to users that they should always use a loop when pollables and streams are involved since a pollable being ready doesn't guarantee there the next read or write will produce/consume more than zero bytes.
Pollable::ready() has more to do with EWOULDBLOCK.
The current docs mention that: If a pollable signals readiness, the next operation MUST NOT return "EWOULDBLOCK" (or however the API in question has WIT-ified that response code).
The proposal is to relax that condition to effectively say: If a pollable signals readiness, the next operation _likely won't_ return "EWOULDBLOCK". But no promises.. #Yolo :P
What Dave just said is what I was thinking for a rewording yeah. Including #yolo too!
Last updated: Jan 24 2025 at 00:11 UTC