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

x/net/proxy: SOCKS5 Timeout is not working properly #37549

Open
qwatros opened this issue Feb 28, 2020 · 6 comments
Open

x/net/proxy: SOCKS5 Timeout is not working properly #37549

qwatros opened this issue Feb 28, 2020 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@qwatros
Copy link

qwatros commented Feb 28, 2020

After successful connection to the proxy timeout doesn't work any more. So it's hanging a long time trying to connect from proxy to an "addr" endpoint (I suppose).

It' would be good to have a global socket timeout option.

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

1.13

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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/root666/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/root666/work/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build754930586=/tmp/go-build -gno-record-gcc-switches"

What did you do?

func Client(socks, addr string) (net.Conn, error) {
	dialer, err := proxy.SOCKS5("tcp", socks, nil, &net.Dialer{Timeout: 3 * time.Second})
	if err != nil {
		return nil, err
	}
	conn, err := dialer.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	return conn, err
}

What did you expect to see?

Timeout with 3 seconds

What did you see instead?

Timeout more then 10 seconds.

@dmitshur dmitshur changed the title x/net/proxy SOCKS5 Timeout is not working properly x/net/proxy: SOCKS5 Timeout is not working properly Mar 2, 2020
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 2, 2020
@dmitshur
Copy link
Contributor

dmitshur commented Mar 2, 2020

/cc @mikioh @bradfitz @ianlancetaylor per owners.

@dmitshur dmitshur added this to the Unreleased milestone Mar 2, 2020
@bradfitz
Copy link
Contributor

bradfitz commented Mar 2, 2020

I think this is a dup of another bug. (or a pending CL or so)

The net.Dialer's timeout is only for the TCP dial. The SOCKS5 dial doesn't support contexts yet.

@ceo0x
Copy link

ceo0x commented Jul 31, 2021

did you manage to make it work ? i think the timeout you are setting is only for the forward proxy parameter, that dialer is used when connecting to the proxy only , not used when trying to connect to "addr"

@Karmaz95
Copy link

BUMP: Did you manage to make it work?

@hut8
Copy link

hut8 commented Jun 22, 2022

It looks like this might be relevant: argoheyard/lang-net@99897dd

@spac3wh1te
Copy link

try this

func main() {
	dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:7890",
		&proxy.Auth{User: "username", Password: "password"},
		nil,
	)

	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	conn, err := dialer.(proxy.ContextDialer).DialContext(ctx, "tcp", "127.0.0.1:80")
	if err != nil {
		fmt.Println("error")
		fmt.Println(err)
	} else {
		fmt.Println("success")
		fmt.Println(conn)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants