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

syscall/js: panic: property readSync is not a function #27773

Closed
AchalaSB opened this issue Sep 20, 2018 · 4 comments
Closed

syscall/js: panic: property readSync is not a function #27773

AchalaSB opened this issue Sep 20, 2018 · 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

@AchalaSB
Copy link

AchalaSB commented Sep 20, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/achala/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/achala/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build813004705=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Running Go code on server . main.go code is working on terminal but not in server.
here's my code

package main

import "fmt"

func main() {
	fmt.Println("Enter First String: ") //Print function is used to display output in same line
	var first string
	fmt.Scanln(&first) // Take input from user
	fmt.Println("Enter Second String: ")
	var second string
	fmt.Scanln(&second)
	fmt.Println(first + second) // Addition of two string
}
<!doctype html>
<!--
Copyright 2018 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>

<head>
	<meta charset="utf-8">
	<title>Go wasm</title>
</head>

<body>

	<script src="wasm_exec.js"></script>

	<script>
		if (!WebAssembly.instantiateStreaming) { // polyfill
			WebAssembly.instantiateStreaming = async (resp, importObject) => {
				const source = await (await resp).arrayBuffer();
				return await WebAssembly.instantiate(source, importObject);
			};
		}

		const go = new Go();
		
		let mod, inst;

		WebAssembly.instantiateStreaming(fetch("lib.wasm"), go.importObject).then((result) => {
			mod = result.module;
			inst = result.instance;
			document.getElementById("runButton").disabled = false;
		});

		async function run() {
			await go.run(inst);
			inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
		}

	</script>

	<button onClick="run();" id="runButton" disabled>Run</button>
</body>
</html>

server.go

package main

import (
	"flag"
	"log"
	"net/http"
)

var (
	listen = flag.String("listen", ":8080", "listen address")
	dir    = flag.String("dir", ".", "directory to serve")
)

func main() {
	flag.Parse()
	log.Printf("listening on %q...", *listen)
	log.Fatal(http.ListenAndServe(*listen, http.FileServer(http.Dir(*dir))))
}

What did you see ?

Getting an error

panic: syscall/js: Value.Call: property readSync is not a function, got undefined [recovered] wasm_exec.js:45:6
	panic: syscall/js: Value.Call: property readSync is not a function, got undefined [recovered] wasm_exec.js:45:6
	panic: syscall/js: Value.Call: property readSync is not a function, got undefined wasm_exec.js:45:6
wasm_exec.js:45:6
goroutine 1 [running]: wasm_exec.js:45:6
fmt.errorHandler(0xc053e28) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:1031 +0x1a wasm_exec.js:45:6
panic(0x12e80, 0xc00e210) wasm_exec.js:45:6
	/usr/lib/go/src/runtime/panic.go:513 +0x1d wasm_exec.js:45:6
syscall.recoverErr(0xc0537d8) wasm_exec.js:45:6
	/usr/lib/go/src/syscall/fs_js.go:493 +0x2b wasm_exec.js:45:6
panic(0x12e80, 0xc00e210) wasm_exec.js:45:6
	/usr/lib/go/src/runtime/panic.go:513 +0x1d wasm_exec.js:45:6
syscall/js.Value.Call(0x7ff8000000000016, 0x2c96b, 0x8, 0xc053828, 0x4, 0x4, 0xc01e048) wasm_exec.js:45:6
	/usr/lib/go/src/syscall/js/js.go:282 +0x79 wasm_exec.js:45:6
syscall.fsCall(0x2c96b, 0x8, 0xc053828, 0x4, 0x4, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/syscall/fs_js.go:472 +0x4 wasm_exec.js:45:6
syscall.Read(0x0, 0xc028260, 0x1, 0x4, 0x14450003, 0x7ff8000300000011, 0xc04c020) wasm_exec.js:45:6
	/usr/lib/go/src/syscall/fs_js.go:374 +0xb wasm_exec.js:45:6
internal/poll.(*FD).Read(0xc02e060, 0xc028260, 0x1, 0x4, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/internal/poll/fd_unix.go:165 +0x18 wasm_exec.js:45:6
os.(*File).read(0xc00c018, 0xc028260, 0x1, 0x4, 0x0, 0x15, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/os/file_unix.go:249 +0x4 wasm_exec.js:45:6
os.(*File).Read(0xc00c018, 0xc028260, 0x1, 0x4, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/os/file.go:108 +0x7 wasm_exec.js:45:6
io.ReadAtLeast(0x3ebe0, 0xc00c018, 0xc028260, 0x1, 0x4, 0x1, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/io/io.go:310 +0x5 wasm_exec.js:45:6
io.ReadFull(0x3ebe0, 0xc00c018, 0xc028260, 0x1, 0x4, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/io/io.go:329 +0x2 wasm_exec.js:45:6
fmt.(*readRune).readByte(0xc028240, 0x4035000000000000, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:321 +0x5 wasm_exec.js:45:6
fmt.(*readRune).ReadRune(0xc028240, 0x0, 0x20, 0xc04c040, 0x15f4d0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:337 +0x1a wasm_exec.js:45:6
fmt.(*ss).ReadRune(0xc02e180, 0x3, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:189 +0x7 wasm_exec.js:45:6
fmt.(*ss).getRune(0xc02e180, 0x12a00) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:211 +0x2 wasm_exec.js:45:6
fmt.(*ss).SkipSpace(0xc02e180) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:422 +0x3 wasm_exec.js:45:6
fmt.(*ss).convertString(0xc02e180, 0x76, 0xc00e1f0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:804 +0x4 wasm_exec.js:45:6
fmt.(*ss).scanOne(0xc02e180, 0x76, 0x10ac0, 0xc00e1f0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:979 +0xcc wasm_exec.js:45:6
fmt.(*ss).doScan(0xc02e180, 0xc053f58, 0x1, 0x1, 0x0, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:1040 +0x8 wasm_exec.js:45:6
fmt.Fscanln(0x3ebe0, 0xc00c018, 0xc048f58, 0x1, 0x1, 0x12e80, 0x1, 0xc00e1f0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:132 +0x3 wasm_exec.js:45:6
fmt.Scanln(0xc048f58, 0x1, 0x1, 0x15, 0x0, 0x0) wasm_exec.js:45:6
	/usr/lib/go/src/fmt/scan.go:70 +0x2 wasm_exec.js:45:6
main.main() wasm_exec.js:45:6
	/home/achala/gocode/tests/src/main.go:8 +0x4 wasm_exec.js:45:6
exit code: 2 wasm_exec.js:67:6
@theclapp
Copy link
Contributor

Since you've posted HTML I assume you're running in a browser. That environment does not support reading from stdin. (I agree that the panic message could use a little work.)

@bcmills
Copy link
Contributor

bcmills commented Sep 22, 2018

CC @neelance @cherrymui

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 22, 2018
@bcmills bcmills added this to the Go1.12 milestone Sep 22, 2018
@bcmills bcmills changed the title panic: syscall/js: Value.Call: property readSync is not a function, got undefined [recovered] syscall/js: panic: property readSync is not a function Sep 22, 2018
@bcmills bcmills added the arch-wasm WebAssembly issues label Sep 22, 2018
@justinclift
Copy link

justinclift commented Sep 22, 2018

@AchalaSB As an idea, the Wasm intro talk by @johanbrandhorst on YouTube might help you get started:

    https://www.youtube.com/watch?v=iTrx0BbUXI4

Have you gone through that yet? 😄

There are also several other tutorials and examples of working Go Wasm code linked to from the wiki page:

    https://github.com/golang/go/wiki/WebAssembly#further-reference-examples

The https://github.com/stdiopt/gowasm-experiments examples should be good to cut-n-paste into your own repo, then modify as needed.

@gopherbot
Copy link

Change https://golang.org/cl/150617 mentions this issue: misc/wasm: add stub for fs.read on browsers

bradfitz pushed a commit that referenced this issue Nov 21, 2018
Using fmt.Scanln in a browser environment caused a panic, since there
was no stub for fs.read. This commit adds a stub that returns ENOSYS.

Fixes #27773.

Change-Id: I79b019039e4bc90da51d71a4edddf3bd7809ff45
Reviewed-on: https://go-review.googlesource.com/c/150617
Run-TryBot: Richard Musiol <neelance@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Nov 20, 2019
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

5 participants