Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

all goroutines are dead asleep - deadlock! wasm docs

オープン
#426 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go, wasm
領域
networking

調査の方向性

cmd/go-ws-client/main.go から始め、提供されている index.html と Makefile のコマンドを使って window.goWS("ws://localhost:8080/ws-chat") の呼び出しを再現します。次に、報告された Dial のスタックフレーム周辺の ws_js.go を調べ、WebAssembly の動作をサーバーの例と比較します。deadlock が説明され、issue に記載された使用方法または再現手順が修正・検証されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

docs

I'm trying to do the next:

Client Code:
//go:build js && wasm

package main

import (
	"context"
	"log"
	"syscall/js"

	"nhooyr.io/websocket"
)

func main() {
	ctx := context.Background()
	window := js.Global()
	window.Set("goWS", js.FuncOf(func(_ js.Value, args []js.Value) any {
		conn, _, err := websocket.Dial(ctx, args[0].String(), nil)
		if err != nil {
			log.Fatal(err)
		}
		goWSObject := window.Get("goWS")
		goWSObject.Set("send", js.FuncOf(func(_ js.Value, args []js.Value) any {
			if err := conn.Write(ctx, websocket.MessageText, []byte(args[0].String())); err != nil {
				log.Fatal(err)
			}
			return nil
		}))
		goWSObject.Set("waitMessage", js.FuncOf(func(_ js.Value, _ []js.Value) any {
			_, bb, err := conn.Read(ctx)
			if err != nil {
				log.Fatal(err)
			}
			return bb
		}))
		return nil
	}))
	waitCh := make(chan struct{})
	<-waitCh
}
index.html:
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>goWS</title>
	<script src="/assets/wasm_exec.js"></script>
	<script>
		const go = new Go();
		WebAssembly.instantiateStreaming(fetch("/assets/app.wasm"), go.importObject)
			.then(res => go.run(res.instance))
	</script>
</head>
<body>
</body>
</html>
Server code:
package main

import (
	"context"
	"net/http"

	"nhooyr.io/websocket"
)

func main() {
	ctx := context.Background()

	http.HandleFunc("/ws-chat", func(w http.ResponseWriter, r *http.Request) {
		conn, err := websocket.Accept(w, r, &websocket.AcceptOptions{
			InsecureSkipVerify: true,
		})
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		_, bb, err := conn.Read(ctx)
		if err != nil {
			conn.Close(websocket.StatusInternalError, err.Error())
			return
		}
		wr, err := conn.Writer(ctx, websocket.MessageText)
		if err != nil {
			conn.Close(websocket.StatusInternalError, err.Error())
			return
		}
		wr.Write(bb)
		wr.Close()
		conn.CloseNow()
	})
	http.ListenAndServe(":8080", http.DefaultServeMux)
}

Also I'm going to attach my Makefile so you can see the commands when I'm compiling:

build_client:
	GOOS=js GOARCH=wasm go build -o dist/assets/app.wasm cmd/go-ws-client/main.go
	cp $(go env GOROOT)/misc/wasm/wasm_exec.js dist/assets/

build_server:
	go build -o dist/bin/app-server cmd/go-ws-server/main.go
Structure of dist folder:
dist/
	- assets/
		- app.wasm
		- wasm_exec.js
	- bin/
		- app-server
	- index.html

But i'm getting the following errors after calling window.goWS("ws://localhost:8080/ws-chat") from the firefox browser's console:

Console:
> window.goWS("ws://localhost:8080/ws-chat")
fatal error: all goroutines are asleep - deadlock! wasm_exec.js:22:14
<empty string>
wasm_exec.js:22:14
goroutine 1 [chan receive]: wasm_exec.js:22:14
main.main() wasm_exec.js:22:14
	/home/oscar/Escritorio/proyecto-react/cmd/go-ws-client/main.go:47 +0xc wasm_exec.js:22:14
<empty string> wasm_exec.js:22:14
goroutine 7 [select]: wasm_exec.js:22:14
nhooyr.io/websocket.dial({0x5aa80, 0x1430050}, {0x1466020, 0x1b}, 0x0) wasm_exec.js:22:14
	/home/oscar/go/pkg/mod/nhooyr.io/websocket@v1.8.10/ws_js.go:320 +0x1c wasm_exec.js:22:14
nhooyr.io/websocket.Dial({0x5aa80, 0x1430050}, {0x1466020, 0x1b}, 0x0) wasm_exec.js:22:14
	/home/oscar/go/pkg/mod/nhooyr.io/websocket@v1.8.10/ws_js.go:289 +0x2 wasm_exec.js:22:14
main.main.func1.1({{}, 0x0, 0x0}, {0x140e0f0, 0x1, 0x1}) wasm_exec.js:22:14
	/home/oscar/Escritorio/proyecto-react/cmd/go-ws-client/main.go:19 +0x4 wasm_exec.js:22:14
syscall/js.handleEvent() wasm_exec.js:22:14
	/usr/local/go/src/syscall/js/func.go:100 +0x26 wasm_exec.js:22:14
exit code: 2 wasm_exec.js:101:14
undefined
主要言語
Go
スター
5.5k
フォーク
377
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

coder/websocket のほかの issue

coder/websocket の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。