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

net: Listen("tcp", "localhost:0") fails on js/wasm #59718

Open
bcmills opened this issue Apr 19, 2023 · 1 comment
Open

net: Listen("tcp", "localhost:0") fails on js/wasm #59718

bcmills opened this issue Apr 19, 2023 · 1 comment
Labels
arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-JS
Milestone

Comments

@bcmills
Copy link
Member

bcmills commented Apr 19, 2023

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

$ gotip version
go version devel go1.21-0853f8ca Fri Apr 14 20:24:18 2023 +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
$ gotip env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/bcmills/.cache/go-build"
GOENV="/usr/local/google/home/bcmills/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/tmp/tmp.GW5wdtYKZr/.gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/tmp.GW5wdtYKZr/.gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/bcmills/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.21-0853f8ca Fri Apr 14 20:24:18 2023 +0000"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.GW5wdtYKZr/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3341472864=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run the following program with GOOS=js GOARCH=wasm:

package main

import (
	"fmt"
	"net"
	"os"

	"golang.org/x/net/nettest"
)

func main() {
	if !nettest.TestableNetwork("tcp") {
		fmt.Println("tcp is not testable")
		os.Exit(1)
	}
	if !nettest.TestableAddress("tcp", "localhost") {
		fmt.Println("localhost is not testable on tcp")
		os.Exit(1)
	}
	l, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		panic(err)
	}
	fmt.Printf("listening on %s\n", l.Addr())
	l.Close()
}

What did you expect to see?

One of the “… is not testable“ messages, or a Listener address.

What did you see instead?

$ GOOS=js GOARCH=wasm go run .
panic: listen tcp: lookup localhost: Protocol not available

goroutine 1 [running]:
main.main()
        /tmp/tmp.GW5wdtYKZr/main.go:22 +0x2a
exit status 2

Perhaps tellingly, net/conn_test.go claims:

// This file implements API tests across platforms and will never have a build
// tag.

but then:

//go:build !js && !wasip1

(introduced in CL 109995)

(attn @golang/wasm)

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. arch-wasm WebAssembly issues OS-JS labels Apr 19, 2023
@bcmills bcmills added this to the Backlog milestone Apr 19, 2023
@gopherbot
Copy link

Change https://go.dev/cl/486315 mentions this issue: all: fix non-gopls short tests on js/wasm and update for wasip1/wasm

gopherbot pushed a commit to golang/tools that referenced this issue Apr 20, 2023
testenv.HasExec should not assume that "js" and "ios" are the only
platforms that can't exec. Instead of hard-coding a list of GOOS,
hard-code only the ones known to work and probe the remainder by
trying to re-exec the test binary.

Similarly, in testenv_notunix, negate the list of unix platforms
instead of hard-coding the non-unix ones.

Add missing calls to testenv functions were needed.

For golang/go#58141.
Updates golang/go#59718.

Change-Id: I0114e0bfb6d091e84b325d7f9bb0896da22482be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/486315
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@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 NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-JS
Projects
None yet
Development

No branches or pull requests

2 participants