Skip to content

Commit c362c85

Browse files
yacovmsykesm
authored andcommitted
[FAB-12082] Appease go vet with cancelations in gossip
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 <yacovm@il.ibm.com>
1 parent 846dcd6 commit c362c85

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

gossip/comm/comm_impl.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,23 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
164164
dialOpts = append(dialOpts, grpc.WithBlock())
165165
dialOpts = append(dialOpts, c.opts...)
166166
ctx := context.Background()
167-
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
167+
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
168+
defer cancel()
168169
cc, err = grpc.DialContext(ctx, endpoint, dialOpts...)
169170
if err != nil {
170171
return nil, errors.WithStack(err)
171172
}
172173

173174
cl := proto.NewGossipClient(cc)
174175

175-
ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
176+
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
176177
defer cancel()
177178
if _, err = cl.Ping(ctx, &proto.Empty{}); err != nil {
178179
cc.Close()
179180
return nil, errors.WithStack(err)
180181
}
181182

182-
ctx, cf := context.WithCancel(context.Background())
183+
ctx, cancel = context.WithCancel(context.Background())
183184
if stream, err = cl.GossipStream(ctx); err == nil {
184185
connInfo, err = c.authenticateRemotePeer(stream, true)
185186
if err == nil {
@@ -194,14 +195,15 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
194195
if !bytes.Equal(actualOrg, oldOrg) {
195196
c.logger.Warning("Remote endpoint claims to be a different peer, expected", expectedPKIID, "but got", pkiID)
196197
cc.Close()
198+
cancel()
197199
return nil, errors.New("authentication failure")
198200
}
199201
}
200202
conn := newConnection(cl, cc, stream, nil)
201203
conn.pkiID = pkiID
202204
conn.info = connInfo
203205
conn.logger = c.logger
204-
conn.cancel = cf
206+
conn.cancel = cancel
205207

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

@@ -271,15 +274,16 @@ func (c *commImpl) Probe(remotePeer *RemotePeer) error {
271274
dialOpts = append(dialOpts, grpc.WithBlock())
272275
dialOpts = append(dialOpts, c.opts...)
273276
ctx := context.Background()
274-
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
277+
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
278+
defer cancel()
275279
cc, err := grpc.DialContext(ctx, remotePeer.Endpoint, dialOpts...)
276280
if err != nil {
277281
c.logger.Debugf("Returning %v", err)
278282
return err
279283
}
280284
defer cc.Close()
281285
cl := proto.NewGossipClient(cc)
282-
ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
286+
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
283287
defer cancel()
284288
_, err = cl.Ping(ctx, &proto.Empty{})
285289
c.logger.Debugf("Returning %v", err)
@@ -292,15 +296,16 @@ func (c *commImpl) Handshake(remotePeer *RemotePeer) (api.PeerIdentityType, erro
292296
dialOpts = append(dialOpts, grpc.WithBlock())
293297
dialOpts = append(dialOpts, c.opts...)
294298
ctx := context.Background()
295-
ctx, _ = context.WithTimeout(ctx, c.dialTimeout)
299+
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
300+
defer cancel()
296301
cc, err := grpc.DialContext(ctx, remotePeer.Endpoint, dialOpts...)
297302
if err != nil {
298303
return nil, err
299304
}
300305
defer cc.Close()
301306

302307
cl := proto.NewGossipClient(cc)
303-
ctx, cancel := context.WithTimeout(context.Background(), defConnTimeout)
308+
ctx, cancel = context.WithTimeout(context.Background(), defConnTimeout)
304309
defer cancel()
305310
if _, err = cl.Ping(ctx, &proto.Empty{}); err != nil {
306311
return nil, err

0 commit comments

Comments
 (0)