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: DialTCP produces "connection refused" error on Linux but not on Windows #38684

Closed
fanmanpro opened this issue Apr 27, 2020 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@fanmanpro
Copy link

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

$ go version
go version go1.14.2 windows/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\\AppData\Local\go-build
set GOENV=C:\Users\\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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\\AppData\Local\Temp\go-build045746270=/tmp/go-build -gno-record-gcc-switches

What did you do?

To reproduce requires two application running and connecting to each other through TCP. So I've made a tiny repo that also includes the powershell build script.
dial-vs-listen

What did you expect to see?

I built the same go code for both Windows and Linux but at runtime the applications produced different results. Specifically with how TCP connections are dialed on each platform.

What did you see instead?

On Windows, when I run the two executables clientA.exe and clientB.exe (built from the build.ps1 script) I get the desired result. As seen in this screenshot:
image

However when I upload and execute the Linux binaries, the result is different:

ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ sudo chmod +x clientA clientB
ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ ls -la
total 10984
drwxrwxr-x 3 ubuntu ubuntu    4096 Apr 27 03:09 .
drwxrwxr-x 4 ubuntu ubuntu    4096 Apr 27 03:08 ..
drwxrwxr-x 8 ubuntu ubuntu    4096 Apr 27 03:08 .git
-rw-rw-r-- 1 ubuntu ubuntu   11255 Apr 27 03:12 A.txt
-rw-rw-r-- 1 ubuntu ubuntu   11255 Apr 27 03:12 B.txt
-rw-rw-r-- 1 ubuntu ubuntu     247 Apr 27 03:08 build.ps1
-rwxrwxr-x 1 ubuntu ubuntu 2950662 Apr 27 03:08 clientA
-rw-rw-r-- 1 ubuntu ubuntu 2642944 Apr 27 03:08 clientA.exe
-rw-rw-r-- 1 ubuntu ubuntu     718 Apr 27 03:08 clientA.go
-rwxrwxr-x 1 ubuntu ubuntu 2950662 Apr 27 03:08 clientB
-rw-rw-r-- 1 ubuntu ubuntu 2642944 Apr 27 03:08 clientB.exe
-rw-rw-r-- 1 ubuntu ubuntu     718 Apr 27 03:08 clientB.go
ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ ./clientA > A.txt & ./clientB > B.txt &
[1] 24914
[2] 24915
ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ cat A.txt
dial tcp4 :2222->:3333: connect: connection refused
ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$ cat B.txt
dial tcp4 :3333->:2222: connect: connection refused
ubuntu@ip-172-31-16-224:~/go/src/github.com/fanmanpro/dial-vs-listen$                                               

I don't expect the connection refused error since these two applications are running under the same environment and the permissions are identical.

@fanmanpro fanmanpro changed the title net.DialTCP produces connection refused error on Linux but not on Windows net.DialTCP produces "connection refused" error on Linux but not on Windows Apr 27, 2020
@andybons andybons changed the title net.DialTCP produces "connection refused" error on Linux but not on Windows net: DialTCP produces "connection refused" error on Linux but not on Windows Apr 27, 2020
@andybons
Copy link
Member

@mikioh @bradfitz

@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Apr 27, 2020
@andybons andybons added this to the Unplanned milestone Apr 27, 2020
@bradfitz
Copy link
Contributor

I guess Linux (at least in its default configuration) doesn't allow such an active/active TCP connection, at least on localhost. Perhaps it's configurable. It'd probably work between two separate hosts, though.

This isn't so much a Go problem as an OS/config difference.

Closing, as I don't see anything to do here.

@golang golang locked and limited conversation to collaborators Apr 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants