Skip to content

Commit 6a6dbc4

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 6a6dbc4

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

pubsub.go

Lines changed: 13 additions & 15 deletions
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,27 @@ 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+
for ctx.Err() == nil {
536528
peerEvt, err := peerEvtHandler.NextPeerEvent(ctx)
537529
if err != nil {
538530
if err != context.Canceled {
539531
log.Warningf("PubsubNewPeer: subscription error in %s: %s", key, err.Error())
540532
}
541533
return nil, err
542534
}
543-
if peerEvt.Type == pubsub.PeerJoin {
544-
pid = peerEvt.Peer
545-
break
535+
536+
if peerEvt.Type != pubsub.PeerJoin {
537+
continue
546538
}
547-
}
548539

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

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

0 commit comments

Comments
 (0)