Hi!
When compiled to wasm, the following small application involving the net/http client completely crashes the Go runtime:
// +build js,wasm
package main
import (
"fmt"
"net/http"
"syscall/js"
)
func doFetch() {
res, err := http.Get("http://localhost:8181")
fmt.Println(res, err)
}
func goFetch(this js.Value, inputs []js.Value) interface{} {
doFetch()
return nil
}
func main() {
fmt.Println("Running doFetch() from wasm directly...")
doFetch()
fmt.Println("Now run goFetch() from javascript (this will crash):")
js.Global().Set("goFetch", js.FuncOf(goFetch))
select {}
}
All that's needed is calling `goFetch()` in the Web browser's console, as you can see in this screenshot:
The interesting part is that executing the GET request directly from Go using `doFetch()` just works fine.
Only if the request is triggered via `goFetch()` from Javascript it crashes.
However, in the Web browsers network monitor it can be seen that the acutal request is sent out but the Go runtime somehow is not able to process the response.
Does anyone have a clue how to debug this problem?
I even tried compiling the example code with the latest Go 1.13 beta version using (albeit with not success):
$ docker run --rm -v $PWD:/src -w /src golang:rc-buster
Any hints are really appreciated!
Thank you very much in advance!
Best regards,
Patrick