-
Notifications
You must be signed in to change notification settings - Fork 12
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
Runtime error with a tinygo built wasi binary. #8
Comments
That should definitely be doable, that's very similar to what https://github.com/GoogleChromeLabs/wasi-fs-access does (minus the ReadableStream but plus File System Access) and it's also based on this library. That "unreachable" error usually happens when Asyncify runs out of its allocated stack space. In this library it's hardcoded to a fairly small number. There was an attempt to allow configuration of stack space in #5 but author has stopped responding at some point. Meanwhile, however, can you try building with optimizations enabled? Those usually significantly reduce the required stack space, which, correspondingly, should also fix the problem. I'm not too familiar with TinyGo, but from the docs sounds like you should just pass |
Then, of course, I'm also not sure if TinyGo uses asyncify for all imports or only for goroutines, but that's probably more in your area of expertise. |
Thanks for the reply. I tried the
That seems important. I think tinygo puts its asyncify stack in the same place where the C stack is (tinygo-org/tinygo#1101 (comment), tinygo-org/tinygo#1101 (comment)). But I can't manage to figure out what position that is exactly.
Actually, not a lot of expertise here too. But I'm afraid you're right. I just tried compiling ...
func pinger(id int) {
for {
time.Sleep(time.Second)
println("ping", id)
}
}
func main() {
go pinger(1)
io.Copy(os.Stdout, os.Stdin)
} and running with ...
func main() {
go pinger(1)
pinger(2)
} works as expected. |
I'm also not sure if |
Yeah wasmer and wasmtime don't support Asyncify, you need a special runtime for it such as the one this library provides. If TinyGo uses Asyncify but doesn't instrument those WASI imports, I'm not sure what you can do here. Either look for configuration that maybe would tell it to instrument those too, or maybe running |
I found that I have no idea if it's possible to make the asyncify scheduler work with goroutines and imports/exports, but Sorry for the bother! And I appreciate the library! |
You might want to raise an issue on TinyGo for that. Since they use Asyncify for goroutines anyway, it means they configure the list of imports/exports somewhere in the compiler. It shouldn't be too hard for them to add a config for extra imports/exports that should be passed to Asyncify too. |
Tinygo wasm binaries are instrumented with asyncify by default. If you inspect the
wasm.wasm
binary from "Steps to Reproduce The Problem" below withwasmer inspect wasm.wasm
, you will see the exportedasyncify_...
functions:When I try running it with this library though, I get what looks like a go panic:
panic: runtime error: deadlocked: no event source
is printed to stdout, and the interpreter throws a runtime error.I'm not really sure if it's the fault with this library, tinygo or my attempt to put these two together. My use case is to run
wasi
compiled go code on the browser wherefd_write
andfd_read
can return asynchronously. I'm trying to write a library where stdin and stdout are exposed as ReadableStreams, and it would be amazing if insidefd_read
an async call likelet chunk = await stdin.getReader().read()
could work.Expected Behavior
I get this if I remove the
async
keywords from the lines"main.add": async function(x, y) {
and"main.result": async function(z) {
lines, then everything works fine.Actual Behavior
This is what I actually get using async imported functions.
Steps to Reproduce the Problem
main.go
:index.html
:main.go
to a wasi target:tinygo build -o wasm.wasm -target wasi main.go
.python3 -m http.server
.Specifications
The text was updated successfully, but these errors were encountered: