Skip to content

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

@bcmills

Description

@bcmills

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-JSarch-wasmWebAssembly issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions