tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.44k stars 911 forks source link

wasm code never returns to javascript after await go.run(instance) #4563

Closed glycerine closed 2 days ago

glycerine commented 2 weeks ago

filing an issue per Ayke's request from gopher slack:

Under tinygo 0.34.0 (and v0.33.0) my javascript can call the wasm but the wasm never returns back to the javascript after the await go.run(instance); like the big Go code does.

I tried calling an explicit os.Exit(0) too, but on execution I get: process.exit is not a function.

Is there some trick to getting the tinygo wasm to finish?

I tested the simplest package main func main() { println("hiya") } program.

(to repro: https://gist.github.com/glycerine/50faaa852a8e41792ea7133732ec1655)

glycerine commented 2 weeks ago

https://github.com/tinygo-org/tinygo/blob/release/targets/wasm_exec.js#L473

seems to hang forever so maybe that is the culprit?

glycerine commented 2 weeks ago

Yes, if I just comment out that line (line 473 targets/wasm_exec.js), things seem to work fine; the wasm code returns to the javascript.

(Not to say there isn't the work Aykevl mentioned on slack to do to make sure everything else (other goroutines?) is finished properly first, just suggesting that removing that wait on a promise that will never resolve will certainly have to be a part of any fix).

glycerine commented 2 days ago

fixed by https://github.com/tinygo-org/tinygo/pull/4567