Skip to content

Commit

Permalink
Don’t close connection if already closing
Browse files Browse the repository at this point in the history
When a peer is shutdown, if the gateway attempts to send a proposal to it, it will fail and the gateway will close the connection and remove it from its registry.
Under stress, with multiple concurrent goroutines all attempting to use and then close the connection, the log gets flooded with the messages:
- (INFO) Attempting to close
- (ERROR) Failed to close.

This commit changes the behaviour so that it checks the grpc state before logging and attempting to close.  If it’s already shutting down, then it’s a no-op.

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
  • Loading branch information
andrew-coleman authored and mastersingh24 committed Oct 30, 2021
1 parent 31bc120 commit d8ee1b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/pkg/gateway/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/internal/pkg/comm"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

type endorser struct {
Expand Down Expand Up @@ -62,7 +63,8 @@ func (ef *endpointFactory) newEndorser(pkiid common.PKIidType, address, mspid st
connectEndorser = peer.NewEndorserClient
}
close := func() error {
if conn != nil {
if conn != nil && conn.GetState() != connectivity.Shutdown {
logger.Infow("Closing connection to remote endorser", "address", address, "mspid", mspid)
return conn.Close()
}
return nil
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/gateway/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ func (reg *registry) removeEndorser(endorser *endorser) {
reg.configLock.Lock()
defer reg.configLock.Unlock()

reg.logger.Infow("Closing connection to remote endorser", "address", endorser.address, "mspid", endorser.mspid)
err := endorser.closeConnection()
if err != nil {
reg.logger.Errorw("Failed to close connection to endorser", "address", endorser.address, "mspid", endorser.mspid, "err", err)
Expand Down

0 comments on commit d8ee1b4

Please sign in to comment.