Skip to content

Commit 29bba1a

Browse files
committed
move connection deadline set below
1 parent bb3c912 commit 29bba1a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

client.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,6 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
260260
netDial = (&net.Dialer{}).DialContext
261261
}
262262

263-
// If needed, wrap the dial function to set the connection deadline.
264-
if deadline, ok := ctx.Deadline(); ok {
265-
forwardDial := netDial
266-
netDial = func(ctx context.Context, network, addr string) (net.Conn, error) {
267-
c, err := forwardDial(ctx, network, addr)
268-
if err != nil {
269-
return nil, err
270-
}
271-
err = c.SetDeadline(deadline)
272-
if err != nil {
273-
c.Close()
274-
return nil, err
275-
}
276-
return c, nil
277-
}
278-
}
279-
280263
// If needed, wrap the dial function to connect through a proxy.
281264
if d.Proxy != nil {
282265
proxyURL, err := d.Proxy(req)
@@ -305,6 +288,23 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
305288
}
306289
}
307290

291+
// If needed, wrap the dial function to set the connection deadline.
292+
if deadline, ok := ctx.Deadline(); ok {
293+
forwardDial := netDial
294+
netDial = func(ctx context.Context, network, addr string) (net.Conn, error) {
295+
c, err := forwardDial(ctx, network, addr)
296+
if err != nil {
297+
return nil, err
298+
}
299+
err = c.SetDeadline(deadline)
300+
if err != nil {
301+
c.Close()
302+
return nil, err
303+
}
304+
return c, nil
305+
}
306+
}
307+
308308
hostPort, hostNoPort := hostPortNoPort(u)
309309
trace := httptrace.ContextClientTrace(ctx)
310310
if trace != nil && trace.GetConn != nil {

0 commit comments

Comments
 (0)