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: add support for fork/exec syscalls? #37100

Open
myitcv opened this issue Feb 7, 2020 · 3 comments
Open

syscall/js: add support for fork/exec syscalls? #37100

myitcv opened this issue Feb 7, 2020 · 3 comments
Labels
arch-wasm WebAssembly issues FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented Feb 7, 2020

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

$ go version
go version devel +b7689f5aa3 Fri Jan 31 06:02:00 2020 +0000 linux/amd64

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
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/playground/go.mod"
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-build703123889=/tmp/go-build -gno-record-gcc-switches"

What did you do?

-- go.mod --
module mod

-- main.go --
package main

import (
        "fmt"
        "os"
        "os/exec"
)

func main() {
        cmd := exec.Command("echo", "hello")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        if err := cmd.Run(); err != nil {
                fmt.Fprintln(os.Stderr, err)
                os.Exit(1)
        }
}
GOOS=js GOARCH=wasm go build -o main.wasm
$(go env GOROOT)/misc/wasm/go_js_wasm_exec main.wasm

What did you expect to see?

hello

What did you see instead?

exec: "echo": executable file not found in $PATH

As some folks on Slack kindly pointed out, this is because GOOS=js ARCH=wasm does not support fork/exec syscalls. Those same folks were not clear that it made sense for this to be supported (especially given the browser focus of this port), but when executing through NodeJS (i.e. the go_js_wasm_exec wrapper) it does have meaning.

Thoughts?

cc @neelance

@myitcv myitcv added the arch-wasm WebAssembly issues label Feb 7, 2020
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 7, 2020
@dmitshur dmitshur added this to the Backlog milestone Feb 7, 2020
@smasher164
Copy link
Member

With the current GOOS=js, we would either need an environment variable like FORKEXEC=on, or some runtime feature detection to allow such a call to take place.

That being said, I think that the general solution to this problem would be to support GOOS=wasi as per #31105. However, the current WASI spec defers fork/exec to a post-MVP version because it is hard to extend to a capability-based design, and doesn't translate well to platforms (windows/web) that can't emulate the syscalls efficiently.

@neelance
Copy link
Member

Fork is a very difficult syscall. I don't see an easy way to support it with Node.js. It is unlikely that I will work on this. Maybe someone else wants to try...

@gopherbot
Copy link

Change https://golang.org/cl/260717 mentions this issue: singleflight: skip tests involving exec on js/wasm

gopherbot pushed a commit to golang/sync that referenced this issue Oct 8, 2020
The js port does not yet support os/exec.

Updates golang/go#37100
Updates golang/go#33519

Change-Id: I9608b7febfdc274dc1b9f34a92d00ef7bea4e13c
Reviewed-on: https://go-review.googlesource.com/c/sync/+/260717
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
sherifabdlnaby pushed a commit to sherifabdlnaby/sync that referenced this issue Feb 24, 2021
The js port does not yet support os/exec.

Updates golang/go#37100
Updates golang/go#33519

Change-Id: I9608b7febfdc274dc1b9f34a92d00ef7bea4e13c
Reviewed-on: https://go-review.googlesource.com/c/sync/+/260717
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly issues FeatureRequest 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