Fix DialContext when using a timeout (#2737)

Fixes #2736
This commit is contained in:
David Drysdale
2019-04-04 17:58:15 +01:00
committed by Menghan Li
parent ea5e6da287
commit d37bd82db6
2 changed files with 49 additions and 6 deletions

View File

@ -138,12 +138,6 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
}
defer func() {
select {
case <-ctx.Done():
conn, err = nil, ctx.Err()
default:
}
if err != nil {
cc.Close()
}
@ -217,6 +211,13 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
ctx, cancel = context.WithTimeout(ctx, cc.dopts.timeout)
defer cancel()
}
defer func() {
select {
case <-ctx.Done():
conn, err = nil, ctx.Err()
default:
}
}()
scSet := false
if cc.dopts.scChan != nil {