@@ -87,29 +87,24 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
87
87
mc .parseTime = mc .cfg .ParseTime
88
88
89
89
// 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
+
90
97
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
- }
97
98
mc .netConn , err = c .cfg .DialFunc (dctx , mc .cfg .Net , mc .cfg .Addr )
98
99
} else {
99
100
dialsLock .RLock ()
100
101
dial , ok := dials [mc .cfg .Net ]
101
102
dialsLock .RUnlock ()
102
103
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
- }
109
104
mc .netConn , err = dial (dctx , mc .cfg .Addr )
110
105
} 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 )
113
108
}
114
109
}
115
110
if err != nil {
0 commit comments