From ec0ef06f7e2552d1554fa4c6d8db1f5fbe28c7fe Mon Sep 17 00:00:00 2001 From: Dingjun Date: Sat, 16 Sep 2017 10:02:20 +0800 Subject: [PATCH] add timeout for dial --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d3b7a6d..823fbb1 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,11 @@ import ( "io" "log" "net" + "time" ) +var dialer = &net.Dialer{Timeout: 10 * time.Second} + func main() { var configfile string @@ -79,9 +82,9 @@ func handleConn(conn net.Conn, b backend) { ServerName: hostname, InsecureSkipVerify: b.Insecure, } - c, err = tls.Dial("tcp", host, config) + c, err = tls.DialWithDialer(dialer, "tcp", host, config) } else { - c, err = net.Dial("tcp", host) + c, err = dialer.Dial("tcp", host) } if err != nil {