The wasm-reduce tool encountered an abnormal timeout under the condition of "--command=./wasmer run test.wasm"
Phenomenon description
Hello, when I use the wasm-reduce tool to shorten the wasm program, there is an abnormal timeout. The command in --command exits normally when executed separately in the terminal, and the exit code is 0. But when using the wasm-reduce tool, the execution is as follows:
Commands from other runtime tools can be executed normally, as follows:
Steps to reproduce
// hello_world.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
emcc hello_world.c -o hello_world.wasm -O2 -s WASM=1
/bin/wasm-reduce hello_world.wasm "--command=/path/to/wasmer run test.wasm" -t test.wasm -w work.wasm
Versions and Environment
binaryen is built from source.
- wasm-reduce: version 123 (version_123-229-g6f4e4f7d0)
- wasmer: 6.0.1
- emcc: 4.0.10 (b7dc6e5747465580df5984e723b9d1f10d8e804b)
- wabt: 1.0.27
- Host OS: Ubuntu 22.04.5 LTS x64
- CPU: 12th Gen Intel® Core™ i7-12700 × 20
Extra Info
If you need any other relevant information, please let me know and I will do my best to provide it. Looking forward to your reply! Thank you!
Can you paste the output of running this:
$ time wasmer run hello_world.wasm
$ cp hello_world.wasm t.wasm
$ time wasmer run t.wasm
The last command should be running the same way wasm-reduce runs it.
If it only fails in wasm-reduce, then my only guess is that subprocesses have some kind of limitation on your system, that is being hit, but I'm not sure what that could be.
One thing you can try is to use --command=bash script.sh and put the VM command in a script file, just on the off chance it is the length of the command somehow (wild guess).
Can you paste the output of running this
just on the off chance it is the length of the command somehow
I tried the way to wrap it into a script. Specifically, I have wrapped a total of five runtime tools to execute commands for wasm files. When the wasmer runtime is present, there is an exception timeout, and when I comment out the wasmer command, the script runs fine.
The script is as follows, and the command about wasmer is on line 37.
/bin/wasm-reduce hello_world.wasm "--command=./multi-check.sh test.wasm" -t test.wasm -w work.wasm
Very strange...
All wasm-reduce does is run popen("timeout 2s $CMD 2> /dev/null"), so perhaps the timeout is a factor here? Otherwise I have no guesses, but perhaps try tinkering with wasm-reduce.cpp's popen logic.
You can also try just using a larger timeout, as the error message says, e.g. --timeout=5.
You can also try just using a larger timeout, as the error message says, e.g. --timeout=5.
I tried to set the --timeout to a larger value, but it still didn't work after waiting for the corresponding time. The result is shown in the first image at the very beginning. [ProgramResult] code: is still 31744.