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: ListenPacket crashes on wasip1/wasm #60739

Closed
bradfitz opened this issue Jun 12, 2023 · 3 comments
Closed

net: ListenPacket crashes on wasip1/wasm #60739

bradfitz opened this issue Jun 12, 2023 · 3 comments
Labels
arch-wasm WebAssembly issues NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bradfitz
Copy link
Contributor

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

$ go version
go version devel go1.21-1fd3cc7cd0 Sun Jun 11 00:41:42 2023 +0000 darwin/arm64

What did you do?

panic: interface conversion: net.sockaddr is *net.UDPAddr, not *net.TCPAddr

goroutine 1 [running]:
net.fakelistener(0x1c8a420, {0x2e1f60, 0x1d0e570})
        /Users/bradfitz/hack/go/src/net/net_fake.go:58 +0x1f
net.socket({0x2e08b8, 0xb60420}, {0x1ce350, 0x4}, 0x3, 0x2, 0x0, 0x1, {0x2e1f60, 0x1d0e570}, ...)
        /Users/bradfitz/hack/go/src/net/net_fake.go:51 +0x7
net.internetSocket({0x2e08b8, 0xb60420}, {0x1ce350, 0x4}, {0x2e1f60, 0x1d0e570}, {0x0, 0x0}, 0x2, 0x0, ...)
        /Users/bradfitz/hack/go/src/net/ipsock_posix.go:142 +0x3
net.(*sysListener).listenUDP(0x1d0d008, {0x2e08b8, 0xb60420}, 0x1d0e570)
        /Users/bradfitz/hack/go/src/net/udpsock_posix.go:226 +0x7
net.(*ListenConfig).ListenPacket(0x1c0a3c0, {0x2e08b8, 0xb60420}, {0x1ce350, 0x4}, {0x1c0c648, 0x2})
        /Users/bradfitz/hack/go/src/net/dial.go:753 +0x1f
tailscale.com/types/nettype.packetListenerAdapter.ListenPacket({{0x2d9700, 0x1c0a3c0}}, {0x2e08b8, 0xb60420}, {0x1ce350, 0x4}, {0x1c0c648, 0x2})
        /Users/bradfitz/src/tailscale.com/types/nettype/nettype.go:54 +0x4

It assumes TCP:

func socket(ctx context.Context, net string, family, sotype, proto int, ipv6only bool, laddr, raddr sockaddr, ctrlCtxFn func(context.Context, string, string, syscall.RawConn) error) (*netFD, error) {
	fd := &netFD{family: family, sotype: sotype, net: net}
	if laddr != nil && raddr == nil {
		return fakelistener(fd, laddr)
	}
	fd2 := &netFD{family: family, sotype: sotype, net: net}
	return fakeconn(fd, fd2, raddr)
}

func fakelistener(fd *netFD, laddr sockaddr) (*netFD, error) {
	l := laddr.(*TCPAddr)
	fd.laddr = &TCPAddr{
		IP:   l.IP,
		Port: nextPort(),
		Zone: l.Zone,
	}
	fd.fakeNetFD = &fakeNetFD{
		listener: true,
		laddr:    fd.laddr,
		incoming: make(chan *netFD, 1024),
	}
	listenersMu.Lock()
	listeners[fd.laddr.(*TCPAddr).String()] = fd
	listenersMu.Unlock()
	return fd, nil
}

/cc @golang/wasm

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. arch-arm Issues solely affecting the 32-bit arm architecture. arch-wasm WebAssembly issues and removed arch-arm Issues solely affecting the 32-bit arm architecture. labels Jun 12, 2023
@seankhliao
Copy link
Member

related #60012

@johanbrandhorst
Copy link
Member

I think https://go-review.googlesource.com/c/go/+/502315 should address this

@gopherbot
Copy link

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

@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 Jun 14, 2023
@dmitshur dmitshur added this to the Go1.21 milestone Jun 14, 2023
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.
Projects
None yet
Development

No branches or pull requests

5 participants