Skip to content

Commit 38e56b0

Browse files
committed
fix: ignore bad peers when fetching the latest value
They may not support the protocol. Or they may just not give us what we're looking for. We might as well keep asking till someone answers.
1 parent eebeec4 commit 38e56b0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pubsub.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (p *PubsubValueStore) handleSubscription(ctx context.Context, ti *topicInfo
478478
case <-ctx.Done():
479479
return
480480
default:
481-
log.Errorf("PubsubPeerJoin: error interacting with new peer", err)
481+
log.Errorf("PubsubPeerJoin: error interacting with new peer: %s", err)
482482
}
483483
}
484484
}
@@ -524,29 +524,29 @@ func (p *PubsubValueStore) handleNewMsgs(ctx context.Context, sub *pubsub.Subscr
524524
}
525525

526526
func (p *PubsubValueStore) handleNewPeer(ctx context.Context, peerEvtHandler *pubsub.TopicEventHandler, key string) ([]byte, error) {
527-
select {
528-
case <-ctx.Done():
529-
return nil, ctx.Err()
530-
default:
531-
}
532-
533-
var pid peer.ID
534-
535-
for {
527+
tried := make(map[peer.ID]bool)
528+
for ctx.Err() == nil {
536529
peerEvt, err := peerEvtHandler.NextPeerEvent(ctx)
537530
if err != nil {
538531
if err != context.Canceled {
539532
log.Warningf("PubsubNewPeer: subscription error in %s: %s", key, err.Error())
540533
}
541534
return nil, err
542535
}
543-
if peerEvt.Type == pubsub.PeerJoin {
544-
pid = peerEvt.Peer
545-
break
536+
537+
pid := peerEvt.Peer
538+
if peerEvt.Type != pubsub.PeerJoin || tried[pid] {
539+
continue
546540
}
547-
}
541+
tried[pid] = true
548542

549-
return p.fetch.Fetch(ctx, pid, key)
543+
value, err := p.fetch.Fetch(ctx, pid, key)
544+
if err == nil {
545+
return value, nil
546+
}
547+
log.Debugf("failed to fetch latest pubsub value for key '%s' from peer '%s': %s", key, pid, err)
548+
}
549+
return nil, ctx.Err()
550550
}
551551

552552
func (p *PubsubValueStore) notifyWatchers(key string, data []byte) {

0 commit comments

Comments
 (0)