Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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--
}
}