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 and wasip1/wasm #59718

Closed
bcmills opened this issue Apr 19, 2023 · 8 comments
Closed

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

bcmills opened this issue Apr 19, 2023 · 8 comments
Labels
arch-wasm WebAssembly issues NeedsFix The path to resolution is known, but the work has not been done. OS-JS
Milestone

Comments

@bcmills
Copy link
Contributor

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>
@gopherbot
Copy link

Change https://go.dev/cl/502315 mentions this issue: net: fix panic when calling net.Listen or net.Dial on wasip1

@bcmills bcmills changed the title net: Listen("tcp", "localhost:0") fails on js/wasm net: Listen("tcp", "localhost:0") fails on js/wasm and wasip1/wasm Aug 25, 2023
@bcmills
Copy link
Contributor Author

bcmills commented Aug 25, 2023

@golang/wasm, is this something that can reasonably be fixed? Dealing with this idiosyncrasy adds significant friction in writing tests.

@johanbrandhorst
Copy link
Member

I'm looking at https://cs.opensource.google/go/x/net/+/refs/tags/v0.14.0:nettest/nettest.go;l=111 and it looks to me like both js and wasip1 should return false for nettest.TestableNetwork, no? Maybe I'm misunderstanding the question?

@bcmills
Copy link
Contributor Author

bcmills commented Aug 25, 2023

@johanbrandhorst , that's for ip. This behavior is for tcp and tcp4.

@johanbrandhorst
Copy link
Member

Ah so the problem is in probeStack. I would have to do some digging, not sure why that identifies tcp as available 🤔. CC @achille-roussel.

@gopherbot
Copy link

Change https://go.dev/cl/526117 mentions this issue: net: enable most tests on wasip1 and js

@bcmills bcmills modified the milestones: Backlog, Go1.22 Jan 20, 2024
@gopherbot
Copy link

Change https://go.dev/cl/557176 mentions this issue: net: remove an unused sync.Map in the fake net implementation

gopherbot pushed a commit that referenced this issue Jan 22, 2024
I added this map in CL 526117, but it is apparently unused.
I assume that I removed all uses of it while revising that change.

Updates #59718.
Updates #50216.

Change-Id: I8cdac39f4764d1fcc31566408304c850cf0f9374
Reviewed-on: https://go-review.googlesource.com/c/go/+/557176
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
I added this map in CL 526117, but it is apparently unused.
I assume that I removed all uses of it while revising that change.

Updates golang#59718.
Updates golang#50216.

Change-Id: I8cdac39f4764d1fcc31566408304c850cf0f9374
Reviewed-on: https://go-review.googlesource.com/c/go/+/557176
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly issues NeedsFix The path to resolution is known, but the work has not been done. OS-JS
Projects
None yet
Development

No branches or pull requests

4 participants