From f271ed415377175038a7cac1ab7171f3667b51b2 Mon Sep 17 00:00:00 2001 From: syumai Date: Wed, 17 Apr 2024 00:02:45 +0900 Subject: [PATCH] add reproduction code of https://github.com/syumai/workers/issues/100 --- syumai-workers-repro-issue-100/.gitignore | 3 ++ syumai-workers-repro-issue-100/Makefile | 12 +++++++ syumai-workers-repro-issue-100/README.md | 35 ++++++++++++++++++++ syumai-workers-repro-issue-100/go.mod | 7 ++++ syumai-workers-repro-issue-100/go.sum | 2 ++ syumai-workers-repro-issue-100/main.go | 14 ++++++++ syumai-workers-repro-issue-100/wrangler.toml | 6 ++++ 7 files changed, 79 insertions(+) create mode 100644 syumai-workers-repro-issue-100/.gitignore create mode 100644 syumai-workers-repro-issue-100/Makefile create mode 100644 syumai-workers-repro-issue-100/README.md create mode 100644 syumai-workers-repro-issue-100/go.mod create mode 100644 syumai-workers-repro-issue-100/go.sum create mode 100644 syumai-workers-repro-issue-100/main.go create mode 100644 syumai-workers-repro-issue-100/wrangler.toml diff --git a/syumai-workers-repro-issue-100/.gitignore b/syumai-workers-repro-issue-100/.gitignore new file mode 100644 index 0000000..7fd93e1 --- /dev/null +++ b/syumai-workers-repro-issue-100/.gitignore @@ -0,0 +1,3 @@ +build +node_modules +.wrangler \ No newline at end of file diff --git a/syumai-workers-repro-issue-100/Makefile b/syumai-workers-repro-issue-100/Makefile new file mode 100644 index 0000000..7f0c8e8 --- /dev/null +++ b/syumai-workers-repro-issue-100/Makefile @@ -0,0 +1,12 @@ +.PHONY: dev +dev: + wrangler dev + +.PHONY: build +build: + go run github.com/syumai/workers/cmd/workers-assets-gen@v0.23.1 -mode=go + GOOS=js GOARCH=wasm go build -o ./build/app.wasm . + +.PHONY: deploy +deploy: + wrangler deploy diff --git a/syumai-workers-repro-issue-100/README.md b/syumai-workers-repro-issue-100/README.md new file mode 100644 index 0000000..0443f78 --- /dev/null +++ b/syumai-workers-repro-issue-100/README.md @@ -0,0 +1,35 @@ +# syumai-workers-repro-issue-100 + +* A reproduction code of https://github.com/syumai/workers/issues/100 + +## Reproduction code + +* A HandlerFunc without writing response body causes weird error. + +```go +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + // doing nothing here causes weird error + }) + workers.Serve(nil) // use http.DefaultServeMux +} +``` + +## How to reproduce + +``` +$ make dev # run this command in another terminal +$ curl localhost:8787 +TypeError: Cannot read properties of undefined (reading 'exports') + at syscall/js.valueNew (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:395:24) + at [object Object] + at [object Object] + at [object Object] + at [object Object] + at [object Object] + at globalThis.Go._resume (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:553:23) + at Object.handleRequest (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/wasm_exec.js:564:8) + at Object.fetch (file:///home/syumai/go/src/github.com/syumai/workers-playground/syumai-workers-repro-issue-100/build/shim.mjs:51:18) + at async jsonError (file:///home/syumai/.nvm/versions/node/v20.12.2/lib/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10) +``` + diff --git a/syumai-workers-repro-issue-100/go.mod b/syumai-workers-repro-issue-100/go.mod new file mode 100644 index 0000000..26fdfc2 --- /dev/null +++ b/syumai-workers-repro-issue-100/go.mod @@ -0,0 +1,7 @@ +module github.com/syumai/workers-playground/syumai-workers-repro-issue-100 + +go 1.21.3 + +toolchain go1.22.2 + +require github.com/syumai/workers v0.23.3 diff --git a/syumai-workers-repro-issue-100/go.sum b/syumai-workers-repro-issue-100/go.sum new file mode 100644 index 0000000..d9793a2 --- /dev/null +++ b/syumai-workers-repro-issue-100/go.sum @@ -0,0 +1,2 @@ +github.com/syumai/workers v0.23.3 h1:7RZwe+EhOhLlFvrDMbgWFf2wc/G17i4uq4GsSG0uNrI= +github.com/syumai/workers v0.23.3/go.mod h1:ZnqmdiHNBrbxOLrZ/HJ5jzHy6af9cmiNZk10R9NrIEA= diff --git a/syumai-workers-repro-issue-100/main.go b/syumai-workers-repro-issue-100/main.go new file mode 100644 index 0000000..29f29a7 --- /dev/null +++ b/syumai-workers-repro-issue-100/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "net/http" + + "github.com/syumai/workers" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + // doing nothing here causes weird error + }) + workers.Serve(nil) // use http.DefaultServeMux +} diff --git a/syumai-workers-repro-issue-100/wrangler.toml b/syumai-workers-repro-issue-100/wrangler.toml new file mode 100644 index 0000000..1612728 --- /dev/null +++ b/syumai-workers-repro-issue-100/wrangler.toml @@ -0,0 +1,6 @@ +name = "go-worker" +main = "./build/worker.mjs" +compatibility_date = "2024-04-15" + +[build] +command = "make build"