You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=js
set GOARCH=wasm
What did you do?
index.html
< html>
< head>
< meta charset="utf-8"/>
< script src="/wasm/wasm_exec.js">< /script>
< script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("/wasm/main.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
< /script>
< script>
function myEvent(event) {
var target = document.getElementById("result2")
var data = GetRecord(1)
target.innerHTML = data //Display the data in the browser
}
< /script>
< /head>
< body>wasm test
< div id="wasm1">< /div>
< div>< b>result1=< /b>< /div>< div id="result1">put the first record here< /div>
< div>< b>result2=< /b>< /div>< div id="result2">put the second record here< /div>
< /body>
< /html>
When the wasm starts up it sends a request to a rest api and the resulting record is displayed in the browser.
When the myEvent() function is triggered it calls the GetRecord function in the wasm and this should display the same record in the browser.
What did you see instead?
When the wasm starts up it the correct result is displayed.
When the myEvent() function is triggered it sends a request to the rest api. The rest api responds but the http.Client.Do function appears to hang. It eventually times out, the record is never received and the error message "context deadline exceeded" is displayed in the browser.
The text was updated successfully, but these errors were encountered:
mdempsky
changed the title
http.Client.Do hangs when called from a wasm function presented to a JS event in a web browser
net/http: Client.Do hangs when called from a wasm function presented to a JS event in a web browser
Dec 22, 2020
I might have been a bit hasty logging this as a bug.
After further investigation and lots of reading the problem is caused by JavaScript's event loop being blocked.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
index.html
main.go https://play.golang.org/p/idrXUU7hxkD
What did you expect to see?
When the wasm starts up it sends a request to a rest api and the resulting record is displayed in the browser.
When the myEvent() function is triggered it calls the GetRecord function in the wasm and this should display the same record in the browser.
What did you see instead?
When the wasm starts up it the correct result is displayed.
When the myEvent() function is triggered it sends a request to the rest api. The rest api responds but the http.Client.Do function appears to hang. It eventually times out, the record is never received and the error message "context deadline exceeded" is displayed in the browser.
The text was updated successfully, but these errors were encountered: