go: net: Listener crashes on windows

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

$ go version
go version go1.15.12 windows/amd64

Does this issue reproduce with the latest release?

Yes, test done with:

  • 1.15.12
  • 1.16.3
  • 1.16.4

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\pc\AppData\Local\go-build
set GOENV=C:\Users\pc\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\pc\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\pc\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\pc\projects\XXXX\XXXX\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\pc\AppData\Local\Temp\go-build555747750=/tmp/go-build -gno-record-gcc-switches

What did you do?

The following program fails when launched directly in the IDE (Goland) and with go run main.go:

package main
​
import (
	"fmt"
	"log"
	"net"
	"runtime"
)
​
func main() {
	//handler := rest.RegisterRoutes()
	log.Println("starting server...")
	//if err := http.ListenAndServe("127.0.0.1:8081", handler); err != nil {
	//	log.Fatalf("could not listen and serve: %v", err)
	//}
	fmt.Println(runtime.GOOS)
	lis, err := net.Listen("tcp", "127.0.0.1:9080") // also tried with "tcp", ":9080"
	if err != nil {
		log.Fatal(err)
	}
	defer lis.Close()
	lis.Accept()
}

The same program is ok when launched in debug directly in the IDE(Goland)

The problem occurs also with windows firewall disabled

What did you expect to see?

A working http server / net listener

What did you see instead?

The following exception:

Goland run Output with listen on "127.0.0.1:9080"

GOROOT=C:\Program Files\Go #gosetup GOPATH=C:\Users\pc\go #gosetup “C:\Program Files\Go\bin\go.exe” build -o C:\Users\pc\AppData\Local\Temp___1xxx.exe XXXX #gosetup C:\Users\pc\AppData\Local\Temp\XXXX.exe #gosetup Exception 0xc0000005 0x0 0x7fff1c490fff 0x28db33c0000 PC=0x28db33c0000 runtime: unknown pc 0x28db33c0000 stack: frame={sp:0xae281ff310, fp:0x0} stack=[0x0,0xae281ffb70) 000000ae281ff210: 000000ae281ff258 000000ae281ff280 000000ae281ff220: 000000ae281ff248 000000ae281ff240 000000ae281ff230: 000000ae281ff244 0000028db31b0f00 000000ae281ff240: 0000000000000000 0000000000000000 000000ae281ff250: 0000000000000000 0000000000000005 000000ae281ff260: 000000ae281ff3a8 00007fff19e9074c 000000ae281ff270: 0000028db31f2f50 00007fff1c50345e 000000ae281ff280: 00007fff1c4d00e8 0000028db321cc70 000000ae281ff290: 00007fff19e90746 000000ae281ff2e0 000000ae281ff2a0: 004f0044004e0049 0053005c00530057 000000ae281ff2b0: 0000028db31f2f50 0000000000000000 000000ae281ff2c0: 0000028db3203320 0066006f00050005 000000ae281ff2d0: 00007fff19e90746 0000000000000000 000000ae281ff2e0: 00007fff00000000 00007fff1c3d00e8 000000ae281ff2f0: 0000000000000000 0000000000000000 000000ae281ff300: 0000000000000001 00007fff1c502513 000000ae281ff310: <0000028d00000001 0000000000000000 000000ae281ff320: 0000000000000000 000000ae281ff418 000000ae281ff330: 0000000000000000 0000000000000000 000000ae281ff340: 0000000000000000 0000000000000000 000000ae281ff350: 0000028db321cc70 00007fff1c469070 000000ae281ff360: 0000028db31f35a0 00007fff1c46aa1c 000000ae281ff370: 0000000000000661 00007fff1a47d3a0 000000ae281ff380: 00007fff1a4496b0 00007fff1c469098 000000ae281ff390: 00007fff1c476f7c 00007fff1a390000 000000ae281ff3a0: 00007fff1c46c3a0 00007fff1c541150 000000ae281ff3b0: 0000000000000000 0000000000000000 000000ae281ff3c0: 0000000000000000 0000000000000000 000000ae281ff3d0: 0000000000000000 000000000000003c 000000ae281ff3e0: 0000000000000004 00007fff1c63a3f0 000000ae281ff3f0: 0000000000000001 000000ae281ff500 000000ae281ff400: 0000028db3203320 00007fff1c52eb58 runtime: unknown pc 0x28db33c0000 stack: frame={sp:0xae281ff310, fp:0x0} stack=[0x0,0xae281ffb70) 000000ae281ff210: 000000ae281ff258 000000ae281ff280 000000ae281ff220: 000000ae281ff248 000000ae281ff240 000000ae281ff230: 000000ae281ff244 0000028db31b0f00 000000ae281ff240: 0000000000000000 0000000000000000 000000ae281ff250: 0000000000000000 0000000000000005 000000ae281ff260: 000000ae281ff3a8 00007fff19e9074c 000000ae281ff270: 0000028db31f2f50 00007fff1c50345e 000000ae281ff280: 00007fff1c4d00e8 0000028db321cc70 000000ae281ff290: 00007fff19e90746 000000ae281ff2e0 000000ae281ff2a0: 004f0044004e0049 0053005c00530057 000000ae281ff2b0: 0000028db31f2f50 0000000000000000 000000ae281ff2c0: 0000028db3203320 0066006f00050005 000000ae281ff2d0: 00007fff19e90746 0000000000000000 000000ae281ff2e0: 00007fff00000000 00007fff1c3d00e8 000000ae281ff2f0: 0000000000000000 0000000000000000 000000ae281ff300: 0000000000000001 00007fff1c502513 000000ae281ff310: <0000028d00000001 0000000000000000 000000ae281ff320: 0000000000000000 000000ae281ff418 000000ae281ff330: 0000000000000000 0000000000000000 000000ae281ff340: 0000000000000000 0000000000000000 000000ae281ff350: 0000028db321cc70 00007fff1c469070 000000ae281ff360: 0000028db31f35a0 00007fff1c46aa1c 000000ae281ff370: 0000000000000661 00007fff1a47d3a0 000000ae281ff380: 00007fff1a4496b0 00007fff1c469098 000000ae281ff390: 00007fff1c476f7c 00007fff1a390000 000000ae281ff3a0: 00007fff1c46c3a0 00007fff1c541150 000000ae281ff3b0: 0000000000000000 0000000000000000 000000ae281ff3c0: 0000000000000000 0000000000000000 000000ae281ff3d0: 0000000000000000 000000000000003c 000000ae281ff3e0: 0000000000000004 00007fff1c63a3f0 000000ae281ff3f0: 0000000000000001 000000ae281ff500 000000ae281ff400: 0000028db3203320 00007fff1c52eb58 rax 0x7fff1a47dd34 rbx 0x7fff1a47dd32 rcx 0x42 rdi 0xffffffffffbadd11 rsi 0x0 rbp 0xae281ff600 rsp 0xae281ff310 r8 0x0 r9 0x0 r10 0x0 r11 0x660 r12 0xc000007a r13 0x0 r14 0x7fff1a47dd34 r15 0x7fff1c3d0000 rip 0x28db33c0000 rflags 0x10202 cs 0x33 fs 0x53 gs 0x2b

Goland run Output with listen on ":9080"

GOROOT=C:\Program Files\Go #gosetup GOPATH=C:\Users\pc\go #gosetup “C:\Program Files\Go\bin\go.exe” build -o C:\Users\pc\AppData\Local\Temp___1xxx.exe xxx #gosetup C:\Users\pc\AppData\Local\Temp___1xxx.exe #gosetup 2021/05/12 15:59:01 starting server… Exception 0xc0000005 0x0 0x7fff1c6d2fff 0x1b854d00000 windows PC=0x1b854d00000 ​ syscall.Syscall6(0x7fff1bf056b0, 0x6, 0x2, 0x1, 0x0, 0x0, 0x0, 0x81, 0x0, 0x0, …) C:/Program Files/Go/src/runtime/syscall_windows.go:343 +0xf2 internal/syscall/windows.WSASocket(0x100000002, 0x0, 0x0, 0x8100000000, 0x0, 0x65b420, 0x7b0298) C:/Program Files/Go/src/internal/syscall/windows/zsyscall_windows.go:321 +0xca net.sysSocket(0x2, 0x1, 0x0, 0x10, 0x7f28e0, 0x10) C:/Program Files/Go/src/net/sock_windows.go:20 +0x66 net.socket(0x71fb90, 0xc0000ac058, 0x6f60d7, 0x3, 0x2, 0x1, 0x0, 0x0, 0x71ff40, 0xc00001a060, …) C:/Program Files/Go/src/net/sock_posix.go:19 +0x65 net.internetSocket(0x71fb90, 0xc0000ac058, 0x6f60d7, 0x3, 0x71ff40, 0xc00001a060, 0x0, 0x0, 0x1, 0x0, …) C:/Program Files/Go/src/net/ipsock_posix.go:141 +0x170 net.(*sysListener).listenTCP(0xc0000d7e38, 0x71fb90, 0xc0000ac058, 0xc00001a060, 0x71f0d8, 0xc00001a060, 0x3) C:/Program Files/Go/src/net/tcpsock_posix.go:168 +0xbe net.(*ListenConfig).Listen(0xc0000d7ed0, 0x71fb90, 0xc0000ac058, 0x6f60d7, 0x3, 0x6f7ba9, 0xe, 0x6ade33, 0x6c6bc5, 0x62a256, …) C:/Program Files/Go/src/net/dial.go:636 +0x5f9 net.Listen(0x6f60d7, 0x3, 0x6f7ba9, 0xe, 0x1, 0x8, 0x0, 0x0) C:/Program Files/Go/src/net/dial.go:706 +0x87 main.main() XXX/main.go:17 +0x10b rax 0x7fff19410b92 rbx 0x7fff19410b90 rcx 0x77 rdi 0xffffffffffbadd11 rsi 0x0 rbp 0x0 rsp 0x26db1fee30 r8 0x97c r9 0x97c r10 0x97c r11 0x97c r12 0xc000007a r13 0x0 r14 0x7fff19410b92 r15 0x7fff1c4d0000 rip 0x1b854d00000 rflags 0x10202 cs 0x33 fs 0x53 gs 0x2b

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Sorry for the delay, I can’t investigate more this problem because it is on my colleague’s machine. I’m closing the issue for the moment. If we find time/situation to do some more testing I’ll reopen this.

Thanks for your help.

Alberto