@@ -87,29 +87,24 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
8787 mc .parseTime = mc .cfg .ParseTime
8888
8989 // Connect to Server
90+ dctx := ctx
91+ if mc .cfg .Timeout > 0 {
92+ var cancel context.CancelFunc
93+ dctx , cancel = context .WithTimeout (ctx , c .cfg .Timeout )
94+ defer cancel ()
95+ }
96+
9097 if c .cfg .DialFunc != nil {
91- dctx := ctx
92- if mc .cfg .Timeout > 0 {
93- var cancel context.CancelFunc
94- dctx , cancel = context .WithTimeout (ctx , c .cfg .Timeout )
95- defer cancel ()
96- }
9798 mc .netConn , err = c .cfg .DialFunc (dctx , mc .cfg .Net , mc .cfg .Addr )
9899 } else {
99100 dialsLock .RLock ()
100101 dial , ok := dials [mc .cfg .Net ]
101102 dialsLock .RUnlock ()
102103 if ok {
103- dctx := ctx
104- if mc .cfg .Timeout > 0 {
105- var cancel context.CancelFunc
106- dctx , cancel = context .WithTimeout (ctx , c .cfg .Timeout )
107- defer cancel ()
108- }
109104 mc .netConn , err = dial (dctx , mc .cfg .Addr )
110105 } else {
111- nd := net.Dialer {Timeout : mc . cfg . Timeout }
112- mc .netConn , err = nd .DialContext (ctx , mc .cfg .Net , mc .cfg .Addr )
106+ nd := net.Dialer {}
107+ mc .netConn , err = nd .DialContext (dctx , mc .cfg .Net , mc .cfg .Addr )
113108 }
114109 }
115110 if err != nil {
0 commit comments