Open qwatros opened 4 years ago
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.
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"
BUMP: Did you manage to make it work?
It looks like this might be relevant: https://github.com/argoheyard/lang-net/commit/99897ddc6eea1f0fb70629190c917a2cf3d8451b
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)
}
}
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
OutputWhat did you do?
What did you expect to see?
Timeout with 3 seconds
What did you see instead?
Timeout more then 10 seconds.