Skip to content

Commit 2d6143f

Browse files
call discover context cancel function to avoid a context leak
1 parent d978518 commit 2d6143f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

p2p/stream/common/streammanager/streammanager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,11 @@ func (sm *streamManager) discover(ctx context.Context) (<-chan libp2p_peer.AddrI
504504
return nil, nil
505505
}
506506

507-
ctx2, _ := context.WithTimeout(ctx, discTimeout)
507+
ctx2, cancel := context.WithTimeout(ctx, discTimeout)
508+
go func() { // avoid context leak
509+
<-time.After(discTimeout)
510+
cancel()
511+
}()
508512
return sm.pf.FindPeers(ctx2, string(sm.myProtoID), discBatch)
509513
}
510514

0 commit comments

Comments
 (0)