Skip to content

Commit 209e053

Browse files
committed
[FAB-12098] Use context WithTimeout in gossip handshake
The handshake is used when connecting to bootstrap or anchor peers, and thead-hoc gRPC stream that is used, is used with a background context without any timeout or cancel. Change-Id: I6d6ae62457e6d13866d68fdb83b3c306460ded03 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 211e63e commit 209e053

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

gossip/comm/comm_impl.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import (
3131
)
3232

3333
const (
34-
defDialTimeout = time.Second * time.Duration(3)
35-
defConnTimeout = time.Second * time.Duration(2)
36-
defRecvBuffSize = 20
37-
defSendBuffSize = 20
34+
handshakeTimeout = time.Second * time.Duration(10)
35+
defDialTimeout = time.Second * time.Duration(3)
36+
defConnTimeout = time.Second * time.Duration(2)
37+
defRecvBuffSize = 20
38+
defSendBuffSize = 20
3839
)
3940

4041
// SecurityAdvisor defines an external auxiliary object
@@ -305,7 +306,9 @@ func (c *commImpl) Handshake(remotePeer *RemotePeer) (api.PeerIdentityType, erro
305306
return nil, err
306307
}
307308

308-
stream, err := cl.GossipStream(context.Background())
309+
ctx, cancel = context.WithTimeout(context.Background(), handshakeTimeout)
310+
defer cancel()
311+
stream, err := cl.GossipStream(ctx)
309312
if err != nil {
310313
return nil, err
311314
}

0 commit comments

Comments
 (0)