Skip to content

Commit

Permalink
[FAB-12082] Appease go vet with cancelations in gossip
Browse files Browse the repository at this point in the history
This change set adds cancelations of the stream cancel function
on all exit paths to appease go vet.

FAB-12082 #done

Change-Id: Ib94d5baaa28ae65b96fbff8e1837b770ed7c6531
Signed-off-by: yacovm <[email protected]>
  • Loading branch information
yacovm authored and sykesm committed Sep 28, 2018
1 parent 846dcd6 commit c362c85
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,23 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
dialOpts = append(dialOpts, grpc.WithBlock())
dialOpts = append(dialOpts, c.opts...)
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
defer cancel()
cc, err = grpc.DialContext(ctx, endpoint, dialOpts...)
if err != nil {
return nil, errors.WithStack(err)
}

cl := proto.NewGossipClient(cc)

ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
defer cancel()
if _, err = cl.Ping(ctx, &proto.Empty{}); err != nil {
cc.Close()
return nil, errors.WithStack(err)
}

ctx, cf := context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(context.Background())
if stream, err = cl.GossipStream(ctx); err == nil {
connInfo, err = c.authenticateRemotePeer(stream, true)
if err == nil {
Expand All @@ -194,14 +195,15 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
if !bytes.Equal(actualOrg, oldOrg) {
c.logger.Warning("Remote endpoint claims to be a different peer, expected", expectedPKIID, "but got", pkiID)
cc.Close()
cancel()
return nil, errors.New("authentication failure")
}
}
conn := newConnection(cl, cc, stream, nil)
conn.pkiID = pkiID
conn.info = connInfo
conn.logger = c.logger
conn.cancel = cf
conn.cancel = cancel

h := func(m *proto.SignedGossipMessage) {
c.logger.Debug("Got message:", m)
Expand All @@ -218,6 +220,7 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
c.logger.Warningf("Authentication failed: %+v", err)
}
cc.Close()
cancel()
return nil, errors.WithStack(err)
}

Expand Down Expand Up @@ -271,15 +274,16 @@ func (c *commImpl) Probe(remotePeer *RemotePeer) error {
dialOpts = append(dialOpts, grpc.WithBlock())
dialOpts = append(dialOpts, c.opts...)
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
defer cancel()
cc, err := grpc.DialContext(ctx, remotePeer.Endpoint, dialOpts...)
if err != nil {
c.logger.Debugf("Returning %v", err)
return err
}
defer cc.Close()
cl := proto.NewGossipClient(cc)
ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
defer cancel()
_, err = cl.Ping(ctx, &proto.Empty{})
c.logger.Debugf("Returning %v", err)
Expand All @@ -292,15 +296,16 @@ func (c *commImpl) Handshake(remotePeer *RemotePeer) (api.PeerIdentityType, erro
dialOpts = append(dialOpts, grpc.WithBlock())
dialOpts = append(dialOpts, c.opts...)
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
defer cancel()
cc, err := grpc.DialContext(ctx, remotePeer.Endpoint, dialOpts...)
if err != nil {
return nil, err
}
defer cc.Close()

cl := proto.NewGossipClient(cc)
ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
defer cancel()
if _, err = cl.Ping(ctx, &proto.Empty{}); err != nil {
return nil, err
Expand Down

0 comments on commit c362c85

Please sign in to comment.