-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output is different when connected to a shell vs a pipe #7833
Comments
Thanks for the report! I can reproduce this behavior as well with the uploaded wasm. That being said though I'm not certian that this is a bug in Wasmtime. Through Would you be able to share the source code of this module? The bug may be in TinyGo's standard library, but it might also be in wasi-libc. This may also be a bug that's since been fixed in wasi-libc and may require a newer build than you might be using. Hard to tell! If you're able to share the original source we can try to help dig in further. Furthermore you mention |
Yeah, since reporting this bug I started to realize it's more likely to be a bug in wasm-libc.
Thanks! I wasn't aware that WASI allowed inspecting the output file type.
It's essentially just testdata/cgo in https://github.com/tinygo-org/tinygo/pull/4101/files but without the |
Nevermind, that was a silly mistake on my side. I can reproduce it using the following steps (this assumes you already have a working TinyGo build):
That's rather involved just to reproduce this issue, I can try to make a reproducer that doesn't use TinyGo. |
Tried again with the main branch of wasi-libc, same issue. So whatever it is, it doesn't look like it's fixed there. |
Update: I can't seem to reproduce this with a simple 'hello world' in C, this needs a bit more investigation. |
Ok, figured it out. I need to call See: |
This flushes stdio, so that functions like puts and printf write out all buffered data even if the output isn't connected to a terminal. For discussion, see: bytecodealliance/wasmtime#7833
This flushes stdio, so that functions like puts and printf write out all buffered data even if the output isn't connected to a terminal. For discussion, see: bytecodealliance/wasmtime#7833
wasmtime
has a different output depending on whether it is run normally or through a pipe (for example,tail
).Test Case
See the wasm.test file here:
wasm-test.zip
Steps to Reproduce
Normal case:
Output is redirected to a pipe:
For comparison, I tested the same thing in
wasmer
and it has the correct (first) output in both cases.Expected Results
Output should be the same, regardless of where stdout is redirected.
Actual Results
The last line is somehow lost when stdout is redirected to a pipe (in this case, passing it to
tail
but I've also seen this issue when running from inside Go os/exec).Versions and Environment
Wasmtime version or commit: wasmtime-cli 17.0.0
Operating system: Linux (Fedora Asahi)
Architecture: aarch64
Extra Info
This is a relatively big test case, I can try to make it smaller if needed.
For example, I've found it reproducible using
fwrite("test\n", 5, 1, stdout);
.The text was updated successfully, but these errors were encountered: