Merge pull request #862 from tamird/fix-conn-leak-again

Avoid goroutine leak in clientconn
This commit is contained in:
Qi Zhao
2016-08-25 14:36:05 -07:00
committed by GitHub

View File

@ -234,13 +234,13 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
defer func() {
select {
case <-ctx.Done():
if conn != nil {
conn.Close()
}
conn = nil
err = ctx.Err()
conn, err = nil, ctx.Err()
default:
}
if err != nil {
cc.Close()
}
}()
for _, opt := range opts {
@ -296,11 +296,9 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
return nil, ctx.Err()
case err := <-waitC:
if err != nil {
cc.Close()
return nil, err
}
case <-timeoutCh:
cc.Close()
return nil, ErrClientConnTimeout
}
// If balancer is nil or balancer.Notify() is nil, ok will be false here.