-
Notifications
You must be signed in to change notification settings - Fork 268
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
wasi stdio is blocking #1531
Comments
Maybe golang wasip1 wasm need some additional config, I have a try with go_js_wasm_exec, that is working gojsExec := fmt.Sprintf("%s/misc/wasm/go_js_wasm_exec", runtime.GOROOT())
cmd := exec.Command("go", "run", "-exec", gojsExec, "./w")
cmd.Env = append(os.Environ(), "GOOS=js", "GOARCH=wasm")
cmd.Stdin = cmdIn
cmd.Stdout = cmdOut
cmd.Stderr = os.Stderr
try.To(cmd.Start())
defer cmd.Wait() |
Hello @shynome, thanks for reporting! I believe this might be due to the stdio streams being in blocking mode. Could you try this patch and report whether it helps address the isssue? |
thanks your reply! but this patch is not working, still has the problem hang up |
I have tried your example and I do think this is a case that would be solved by having the stdio streams set to non-blocking. If I use the
This is the diff I used on your program: $ git diff
diff --git a/main.go b/main.go
index 6baf1e4..ed77085 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,8 @@ import (
func main() {
var callSystemExec bool
flag.BoolVar(&callSystemExec, "sys", false, "use system exec")
+ var useWasirun bool
+ flag.BoolVar(&useWasirun, "wasirun", false, "use wasirun call")
var useWasmer bool
flag.BoolVar(&useWasmer, "wasmer", false, "use wasm3 call")
var useGoJS bool
@@ -41,6 +43,19 @@ func main() {
cmd.Stderr = os.Stderr
try.To(cmd.Start())
defer cmd.Wait()
+ } else if useWasirun {
+ // build wasip1
+ build := exec.Command("gotip", "build", "-o", "w.wasm", "./w")
+ build.Env = append(os.Environ(), "GOOS=wasip1", "GOARCH=wasm")
+ build.Stderr = os.Stderr
+ try.To(build.Run())
+
+ cmd := exec.Command("wasirun", "--non-blocking-stdio", "--", "w.wasm")
+ cmd.Stdin = cmdIn
+ cmd.Stdout = cmdOut
+ cmd.Stderr = os.Stderr
+ try.To(cmd.Start())
+ defer cmd.Wait()
} else if useWasmer {
// build wasip1
build := exec.Command("gotip", "build", "-o", "w.wasm", "./w") Now if I remove I also tried the patch that I pointed out to you and it seems to also address the issue, this is the diff I used: $ git diff
diff --git a/main.go b/main.go
index 6baf1e4..e835246 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,8 @@ import (
func main() {
var callSystemExec bool
flag.BoolVar(&callSystemExec, "sys", false, "use system exec")
+ var useWasirun bool
+ flag.BoolVar(&useWasirun, "wasirun", false, "use wasirun call")
var useWasmer bool
flag.BoolVar(&useWasmer, "wasmer", false, "use wasm3 call")
var useGoJS bool
@@ -41,6 +43,19 @@ func main() {
cmd.Stderr = os.Stderr
try.To(cmd.Start())
defer cmd.Wait()
+ } else if useWasirun {
+ // build wasip1
+ build := exec.Command("../../../go.googlesource.com/go/bin/go", "build", "-o", "w.wasm", "./w")
+ build.Env = append(os.Environ(), "GOROOT=../../../go.googlesource.com/go", "GOOS=wasip1", "GOARCH=wasm")
+ build.Stderr = os.Stderr
+ try.To(build.Run())
+
+ cmd := exec.Command("wasirun", "--", "w.wasm")
+ cmd.Stdin = cmdIn
+ cmd.Stdout = cmdOut
+ cmd.Stderr = os.Stderr
+ try.To(cmd.Start())
+ defer cmd.Wait()
} else if useWasmer {
// build wasip1
build := exec.Command("gotip", "build", "-o", "w.wasm", "./w") Let me know if you have any trouble reproducing the findings! |
ohhhh, it is working! Thanks for your help. It seems wazero also need a or leave it to third-party library like wasi-go? |
nonblocking stdio is definitely something I should circle back to 😬 #1500 |
Related: #1538 |
so I think this actually works on
the reason is that if you instantiate wazero as a library and you pass in the pipe, then we cannot treat it as an OS file descriptor (to us it will be an opaque io.Reader or io.Writer), and thus we cannot set nonblocking mode. Let me know if this works. |
it is working! cmdIn, cmdWriter := try.To2(os.Pipe())
cmdReader, cmdOut := try.To2(os.Pipe())
...
mc := wazero.NewModuleConfig().
WithArgs("wazero").
WithRandSource(rand.Reader).
WithSysNanosleep().
WithSysNanotime().
WithSysWalltime().
WithStdin(cmdIn).
WithStdout(cmdOut).
WithStderr(os.Stderr) Thanks for all people work! |
awesome! ah yes, the trick is you're using os.Pipe() instead of an io.Pipe() :) |
Describe the bug
goroutines is not running
more details: https://github.com/shynome/wazero-yamux-stdio-test
add log at
yamux/session.go#L636
, the log ingoroutines
is not running in wasmTo Reproduce
Expected behavior
work the same as system call
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the relevant information):
Additional context
maybe this is a golang wasm problem, but I can't verify
The text was updated successfully, but these errors were encountered: