From f2ceccca6543dc06f0323b1dc994052058e58d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=CC=88=D0=B4=D0=BE=D1=80=20=D0=9F=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D1=81=D0=BA=D0=B8=D0=B8=CC=86?= Date: Fri, 24 Sep 2021 10:53:02 +0300 Subject: [PATCH 1/2] the lastClose parameter should be updated when closing only after a successful opening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Фёдор Партанский --- pkg/fab/comm/connector.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/fab/comm/connector.go b/pkg/fab/comm/connector.go index 7537ba24cf..77254d6ef1 100644 --- a/pkg/fab/comm/connector.go +++ b/pkg/fab/comm/connector.go @@ -124,9 +124,9 @@ 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) @@ -160,7 +160,7 @@ func (cc *CachingConnector) ReleaseConn(conn *grpc.ClientConn) { } logger.Debugf("ReleaseConn [%s]", cconn.target) - setClosed(cconn) + setClosed(cconn, nil) cc.ensureJanitorStarted() } @@ -342,9 +342,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-- } } From c750e0d790980b799acee7b28c526aface6df75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=CC=88=D0=B4=D0=BE=D1=80=20=D0=9F=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D1=81=D0=BA=D0=B8=D0=B8=CC=86?= Date: Fri, 24 Sep 2021 11:35:28 +0300 Subject: [PATCH 2/2] the lastClose parameter should be updated when closing only after a successful opening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Фёдор Партанский --- pkg/fab/comm/connector.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/fab/comm/connector.go b/pkg/fab/comm/connector.go index 77254d6ef1..d6fc04dbc9 100644 --- a/pkg/fab/comm/connector.go +++ b/pkg/fab/comm/connector.go @@ -129,6 +129,7 @@ func (cc *CachingConnector) DialContext(ctx context.Context, target string, opts setClosed(c, err) cc.removeConn(c) cc.lock.Unlock() + return nil, errors.WithMessagef(err, "dialing connection on target [%s]", target) } return c.conn, nil