I am implementing nonblocking stdin support for Wasmer and Wasmer JS. During exploring the code, I noticed that fd_read never timed out and is blocked indefinitely despite the detection of NONBLOCK status flag. __asyncify_light was supposed to handle that timeout parameter and errored out, just like what was done in __asyncify_with_deep_sleep, but it appeared to be ignored.
Given all the usage of __asyncify_light are either supplying zero timeout as a nonblocking mechanism or does not use timeout at all, the timeout parameter can be replaced with a simple bool. Most polling logic use the with_deep_sleep version. I guess that the distinction is that not all environment (e.g., Wasmer JS SDK without COEP/COOP) supports deep sleeping.
I use my own fork to reproduce. It is based on an old version, v4.2.5, used by Wasm.js, but this issue presents in the main branch.
N/A because nonblocking read is not available under normal circumstances, but it might be patched like above to allow one. It is actually better tested in Wasmer JS SDK since the blocking read from Tokio's stdin implementation cannot be cancelled. I can provide more context if required.
Expected behavior
Under nonblocking mode set to stdin (fd=0), fd_read returns immediately no matter whether any data is available.
Actual behavior
fd_read blocks until some data is available.
Additional context
To work toward a fix, I would like to first understand the distinction between the light version and the deep sleep one, and if a zero-or-infinite timeout makes sense, e.g., actually "lighter", provides more compatibility, etc.
Describe the bug
I am implementing nonblocking stdin support for Wasmer and Wasmer JS. During exploring the code, I noticed that
fd_read
never timed out and is blocked indefinitely despite the detection ofNONBLOCK
status flag.__asyncify_light
was supposed to handle thattimeout
parameter and errored out, just like what was done in__asyncify_with_deep_sleep
, but it appeared to be ignored.Given all the usage of
__asyncify_light
are either supplying zero timeout as a nonblocking mechanism or does not use timeout at all, the timeout parameter can be replaced with a simplebool
. Most polling logic use thewith_deep_sleep
version. I guess that the distinction is that not all environment (e.g., Wasmer JS SDK without COEP/COOP) supports deep sleeping.I use my own fork to reproduce. It is based on an old version, v4.2.5, used by Wasm.js, but this issue presents in the main branch.
Steps to reproduce
N/A because nonblocking read is not available under normal circumstances, but it might be patched like above to allow one. It is actually better tested in Wasmer JS SDK since the blocking read from Tokio's stdin implementation cannot be cancelled. I can provide more context if required.
Expected behavior
Under nonblocking mode set to stdin (fd=0),
fd_read
returns immediately no matter whether any data is available.Actual behavior
fd_read
blocks until some data is available.Additional context
To work toward a fix, I would like to first understand the distinction between the light version and the deep sleep one, and if a zero-or-infinite timeout makes sense, e.g., actually "lighter", provides more compatibility, etc.