-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issuesWebAssembly issues
Description
What version of Go are you using (go version
)?
$ go version go1.13.6
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 GO111MODULE=on set GOARCH=wasm set GOBIN= set GOCACHE=C:\Users\Administrator\AppData\Local\go-build set GOENV=C:\Users\Administrator\AppData\Roaming\go\env set GOEXE= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GONOPROXY= set GONOSUMDB= set GOOS=js set GOPATH=C:\Users\Administrator\go set GOPRIVATE= set GOPROXY=https://goproxy.cn,direct set GOROOT=C:\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set GOWASM= set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=0 set GOMOD=C:\Users\Administrator\go\src\wasm\go.mod 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=-fPIC -fmessage-length=0 -fdebug-prefix-map=C:\Users\Administrator\AppData\Local\Temp\go-build171043022=/tmp/go-build -gno-record-gcc-switches
What did you do?
I want hide my http request in go-wasm as the js-lib, my js code call go-wasm do the http request. See my demo as below:
$ main.go: func main() { fmt.Println("Start go...") goObj := js.Global().Get("goObj") if goObj == js.Undefined() { fmt.Println("No goObj Object in global.") return } goObj.Set("version", version) goObj.Set("httpByGo", js.FuncOf(func(this js.Value, args []js.Value) interface{} { fmt.Println("Start httpByGo...") resChan := make(chan interface{}) go func() { fmt.Println("Start http...") resp, err := http.Get("http://localhost:3000/demo.json") fmt.Println("11111111111111") defer resp.Body.Close() fmt.Println("22222222222222") body, err := ioutil.ReadAll(resp.Body) fmt.Println("3333333333333") log.Fatal(err.Error()) resChan <- body fmt.Println("4444444444444") }() fmt.Println("5555555555555555") res := <- resChan fmt.Println("6666666666666666") return res })) wg := sync.WaitGroup{} wg.Add(1) wg.Wait() }
$ web.js $(function () { const go = new Go(); WebAssembly.instantiateStreaming(fetch("go.wasm"), go.importObject).then((result) => { go.run(result.instance); goObj.httpByGo(); }); }); var goObj = {};
$ demo.json { "code": 200, "data": { "pageId": "1799490" } }
What did you expect to see?
exprect to see the demo.json in console log.
What did you see instead?
log as below:
Start http... fatal error: all goroutines are asleep - deadlock! goroutine 1 [semacquire]: sync.runtime_Semacquire(0x41e178) C:/Go/src/runtime/sema.go:56 +0x2 sync.(*WaitGroup).Wait(0x41e170) C:/Go/src/sync/waitgroup.go:130 +0x10 main.main() C:/Users/Administrator/go/src/wasm/wasm.go:47 +0x13 goroutine 7 [select]: net/http.(*Transport).RoundTrip(0x37ee60, 0x48c000, 0x0, 0x0, 0x0) C:/Go/src/net/http/roundtrip_js.go:169 +0x51 net/http.send(0x48c000, 0xde200, 0x37ee60, 0x0, 0x0, 0x0, 0x0, 0x40c040, 0x428b10, 0x1) C:/Go/src/net/http/client.go:250 +0x5c net/http.(*Client).send(0x38b1e0, 0x48c000, 0x0, 0x0, 0x0, 0x40c040, 0x0, 0x1, 0x85100) C:/Go/src/net/http/client.go:174 +0x13 net/http.(*Client).do(0x38b1e0, 0x48c000, 0x0, 0x0, 0x0) C:/Go/src/net/http/client.go:641 +0x35 net/http.(*Client).Do(...) C:/Go/src/net/http/client.go:509 net/http.(*Client).Get(0x38b1e0, 0x965a9, 0x1f, 0x1, 0x1, 0xe) C:/Go/src/net/http/client.go:398 +0xe net/http.Get(...) C:/Go/src/net/http/client.go:370 main.main.func1.1(0x4300c0) C:/Users/Administrator/go/src/wasm/main.go:29 +0x7 created by main.main.func1 C:/Users/Administrator/go/src/wasm/main.go:27 +0x7
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issuesWebAssembly issues