fix: do not block ctx.Done() on peer discovery

This commit is contained in:
Richard Ramos 2023-05-09 17:25:58 -04:00 committed by RichΛrd
parent e14c55c263
commit fa61e58d3b
2 changed files with 11 additions and 2 deletions

View File

@ -294,8 +294,13 @@ func (d *DiscoveryV5) iterate(ctx context.Context) error {
} }
if len(peerAddrs) != 0 { if len(peerAddrs) != 0 {
d.peerConnector.PeerChannel() <- peerAddrs[0] select {
case d.peerConnector.PeerChannel() <- peerAddrs[0]:
case <-ctx.Done():
return nil
}
} }
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil

View File

@ -124,7 +124,11 @@ func (r *Rendezvous) discover(ctx context.Context) {
server.Unlock() server.Unlock()
for _, addr := range addrInfo { for _, addr := range addrInfo {
r.peerConnector.PeerChannel() <- addr select {
case r.peerConnector.PeerChannel() <- addr:
case <-ctx.Done():
return
}
} }
} else { } else {
// TODO: change log level to DEBUG in go-libp2p-rendezvous@v0.4.1/svc.go:234 discover query // TODO: change log level to DEBUG in go-libp2p-rendezvous@v0.4.1/svc.go:234 discover query