From 3815b13ad5e03180a737b53afb4170a9d9d0aabd Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 12 Jun 2021 05:58:14 -0500 Subject: [PATCH] use DialContext --- src/core/tcp.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/tcp.go b/src/core/tcp.go index 21a3ba7..c5487d5 100644 --- a/src/core/tcp.go +++ b/src/core/tcp.go @@ -270,7 +270,9 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) { if err != nil { return } - conn, err = dialer.Dial("tcp", saddr) + ctx, done := context.WithTimeout(context.Background(), default_timeout) + conn, err = dialer.(proxy.ContextDialer).DialContext(ctx, "tcp", saddr) + done() if err != nil { return } @@ -292,7 +294,6 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) { } dialer := net.Dialer{ Control: t.tcpContext, - Timeout: time.Second * 5, } if sintf != "" { dialer.Control = t.getControl(sintf) @@ -338,7 +339,9 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) { } } } - conn, err = dialer.Dial("tcp", dst.String()) + ctx, done := context.WithTimeout(context.Background(), default_timeout) + conn, err = dialer.DialContext(ctx, "tcp", dst.String()) + done() if err != nil { t.links.core.log.Debugf("Failed to dial %s: %s", callproto, err) return