Skip to content
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: deadlock on blocking call #39928

Closed
pigfox opened this issue Jun 29, 2020 · 4 comments
Closed

runtime: deadlock on blocking call #39928

pigfox opened this issue Jun 29, 2020 · 4 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pigfox
Copy link

pigfox commented Jun 29, 2020

This happens when compiling Go code into wasm with:
GOOS=js GOARCH=wasm go build -o ./Go/assets/main.wasm wasm.go

What version of Go are you using (go version)?

$ go version
go1.14.4 linux/amd64

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/peter/.cache/go-build"
GOENV="/home/peter/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/go:/home/peter/work"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/5830"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/5830/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build651075817=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempted to make a request from compiled Wasm code.

func query(this js.Value, args []js.Value) interface{} {
	var rv interface{}

	c1 := make(chan string)
	go func() {
		c1 <- makeRequest()
	}()

	target:= fmt.Sprintf("%s", args[0]) + "Result"

	select {
	case color := <-c1:
		js.Global().Get("document").Call("getElementById", target).Set("innerHTML", color)
	}
	return rv
}

What did you expect to see?

A string in a HTML element.

What did you see instead?

fatal error: all goroutines are asleep - deadlock!
wasm_exec.js:47
wasm_exec.js:47 goroutine 1 [select (no cases)]:

@dmitshur dmitshur added arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jun 30, 2020
@dmitshur dmitshur added this to the Backlog milestone Jun 30, 2020
@dmitshur dmitshur changed the title fatal error: all goroutines are asleep - deadlock! runtime: deadlock on blocking call Jun 30, 2020
@dmitshur
Copy link
Contributor

Thanks for reporting. This may be a problem in the code rather than the Go runtime. In order to investigate, we'll need to know how query being called. Can you provide more information on that please?

@neelance Is there a restriction on where blocking calls can be made (e.g., inside callbacks), and do you know if we've documented it somewhere? I'm not finding it in https://golang.org/wiki/WebAssembly.

@agnivade
Copy link
Contributor

It is documented here: https://golang.org/pkg/syscall/js/#FuncOf.

@pigfox
Copy link
Author

pigfox commented Jun 30, 2020

@dmitshur You can clone the repo: https://github.com/pigfox/wasm and view the error.

@dmitshur dmitshur removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 30, 2020
@dmitshur
Copy link
Contributor

dmitshur commented Jun 30, 2020

Yep, that code is making query the callback handler by setting an element's onclick property:

onclick="query('colors');

The deadlock is working as intended per documentation at https://golang.org/pkg/syscall/js/#FuncOf. (Thanks @agnivade.) To avoid the deadlock, you'll need to follow the suggestion of ensuring the callback itself is non-blocking.

@golang golang locked and limited conversation to collaborators Jun 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants