Heap-Hop opened PR #10113 from Heap-Hop:fix_stream_blocking
to bytecodealliance:main
:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
issue #9667The
InputStream::ready
can be prematurely triggered byio::ErrorKind::WouldBlock
. This PR fixesblocking_read
to return the correct data.
Heap-Hop requested pchickey for a review on PR #10113.
Heap-Hop requested wasmtime-core-reviewers for a review on PR #10113.
pchickey submitted PR review.
pchickey commented on PR #10113:
Thanks. As you said in the other thread, there's no real way to test this operation from inside because it blocks. I am fine landing this without a test.
badeend commented on PR #10113:
The change seems fine indeed.
Aside from
blocking_read
, its counterpart of the writable side (write_ready
) probably needs similar treatment as well. I think it should loop whilecheck_write
returnsOk(0)
.
Heap-Hop commented on PR #10113:
loop { // This `ready` call may return early due to `io::ErrorKind::WouldBlock`. self.ready().await; let data = self.read(size)?; if data.is_empty() { continue; } return Ok(data); }
Can we ensure that there won't be infinite or excessive invalid loops here?
badeend commented on PR #10113:
As a fail-safe, you could keep track of the number of iterations and return a trap if it exceeds _{some number}_. The reason I suggest to trap as opposed to return an empty buffer, is because after a certain threshold it's more likely to be a bug in the
InputStream
implementation.
Heap-Hop commented on PR #10113:
I noticed that
io::ErrorKind::WouldBlock
is already handled here.
However, considering that this trait might still be implemented elsewhere, it indeed makes sense to perform a loop incheck_write
.
Heap-Hop commented on PR #10113:
you could keep track of the number of iterations and return a trap if it exceeds {some number}.
I believe this requires further discussion before implementation.
How to determine the maximum value and how to define the error.
Heap-Hop edited a comment on PR #10113:
you could keep track of the number of iterations and return a trap if it exceeds {some number}.
I believe this requires further discussion before implementation.
How to determine thenumber
and how to define the error.
alexcrichton commented on PR #10113:
I think it'd be reasonable to pick a small arbitrary number, for example 10, as the limit of turns of the loop. If something is spuriously readable/writable 10 times in a row that seems indicative of a bug
Heap-Hop updated PR #10113.
Heap-Hop edited PR #10113.
Heap-Hop edited PR #10113:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
issue #9667The
InputStream::ready
can be prematurely triggered byio::ErrorKind::WouldBlock
. This PR ensure thatblocking_
functions return a valid non-empty result.
alexcrichton commented on PR #10113:
I believe the test failure can be fixed by checking if the blocking_read size is zero, and in such a case avoiding the loop entirely or basically doing the read once and returning the result instead of turning the loop again.
Heap-Hop updated PR #10113.
alexcrichton merged PR #10113.
Last updated: Feb 28 2025 at 02:27 UTC