Skip to content

wasm: fatal error: all goroutines are asleep - deadlock! #34478

@danaugrs

Description

@danaugrs

Version: go1.13 windows/amd64
Does this issue reproduce with the latest release? Yes

go env Output
set GO111MODULE=
set GOARCH=wasm
set GOBIN=
set GOCACHE=C:\Users\danau\AppData\Local\go-build
set GOENV=C:\Users\danau\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=js
set GOPATH=C:\projects\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\danau\AppData\Local\Temp\go-build158127038=/tmp/go-build -gno-record-gcc-switches

Minimal Reproducible Example

package main

import (
	"fmt"
	"syscall/js"
)

func doStuffSynchronously() {
	done := make(chan bool)
	f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		fmt.Println("DOING STUFF")
		done <- true
		return nil
	})
	defer f.Release()
	js.Global().Call("setTimeout", f, 1000)
	<-done
	fmt.Println("DONE DOING STUFF")
}

func main() {
	
	doStuffSynchronously() // <- WORKS HERE

	cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		fmt.Println("CB CALLED")
		doStuffSynchronously() // <- CRASHES WITH "fatal error: all goroutines are asleep - deadlock!"
		return nil
	})
	defer cb.Release()
	js.Global().Call("setTimeout", cb, 1000)

	// Prevent app from finishing while we wait for callback to execute
	neverDone := make(chan bool)
	<-neverDone
}

What did you expect to see?

I expected doStuffSynchronously() to work inside a callback just like it works outside one.

What did you see instead?

fatal error: all goroutines are asleep - deadlock!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions