Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cachedConn lastClose update specified #191

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
14 changes: 9 additions & 5 deletions pkg/fab/comm/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ func (cc *CachingConnector) DialContext(ctx context.Context, target string, opts

cc.lock.Unlock()

if err := cc.openConn(ctx, c); err != nil {
if err = cc.openConn(ctx, c); err != nil {
cc.lock.Lock()
setClosed(c)
setClosed(c, err)
cc.removeConn(c)
cc.lock.Unlock()

return nil, errors.WithMessagef(err, "dialing connection on target [%s]", target)
}
return c.conn, nil
Expand Down Expand Up @@ -160,7 +161,7 @@ func (cc *CachingConnector) ReleaseConn(conn *grpc.ClientConn) {
}
logger.Debugf("ReleaseConn [%s]", cconn.target)

setClosed(cconn)
setClosed(cconn, nil)

cc.ensureJanitorStarted()
}
Expand Down Expand Up @@ -342,9 +343,12 @@ func closeConn(conn *grpc.ClientConn) {
cancel()
}

func setClosed(cconn *cachedConn) {
func setClosed(cconn *cachedConn, err error) {
if cconn.open > 0 {
cconn.lastClose = time.Now()
if err == nil {
cconn.lastClose = time.Now()
}

cconn.open--
}
}