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: Dialer.Dial failed to establish connection on Ubuntu #21404

Closed
Ken-Miura opened this issue Aug 11, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@Ken-Miura
Copy link

commented Aug 11, 2017

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

go version go1.8.3 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/kmiura/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build271721950=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

tried to establish tcp connection.
Link on play.golang.org (https://play.golang.org/p/sOmgtkxQhx)

What did you expect to see?

Dialer.Dial succeeded in establishing connection on Ubuntu.

What did you see instead?

Dialer.Dial failed to establish connection with message "dial tcp :20->:8081: bind: address already in use".

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 11, 2017

Your program is trying to make initiate TCP connections from the same local port. The only way to implement that with the sockets API is to bind the socket before making the connect call. Calling bind on the first socket will work, but calling bind on the second socket will fail, because the first socket is already bound to that port.

Closing because I don't see any way that Go could change to make this program work.

In general, if you have questions about using Go, please don't use the issue tracker. See the forums at https://golang.org/wiki/Questions.

@golang golang locked and limited conversation to collaborators Aug 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.