Skip to content

Commit 06f57bb

Browse files
authored
refactor(p2p): subscriber.Stop logs but ignores error from unregister topic validator (#127)
1 parent cb11d8c commit 06f57bb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

p2p/subscriber.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func NewSubscriber[H header.Header[H]](
7575
}, nil
7676
}
7777

78-
// Start starts the Subscriber, registering a topic validator for the "header-sub"
79-
// topic and joining it.
78+
// Start starts the Subscriber and joins the instance's topic. SetVerifier must
79+
// be called separately to ensure a validator is mounted on the topic.
8080
func (s *Subscriber[H]) Start(context.Context) (err error) {
8181
log.Infow("joining topic", "topic ID", s.pubsubTopicID)
8282
s.topic, err = s.pubsub.Join(s.pubsubTopicID, pubsub.WithTopicMessageIdFn(s.msgID))
@@ -85,14 +85,15 @@ func (s *Subscriber[H]) Start(context.Context) (err error) {
8585

8686
// Stop closes the topic and unregisters its validator.
8787
func (s *Subscriber[H]) Stop(context.Context) error {
88-
err := s.pubsub.UnregisterTopicValidator(s.pubsubTopicID)
89-
if err != nil {
90-
log.Warnf("unregistering validator: %s", err)
88+
regErr := s.pubsub.UnregisterTopicValidator(s.pubsubTopicID)
89+
if regErr != nil {
90+
// do not return this error as it is non-critical and usually
91+
// means that a validator was not mounted.
92+
log.Warnf("unregistering validator: %s", regErr)
9193
}
9294

93-
err = errors.Join(err, s.topic.Close())
94-
err = errors.Join(err, s.metrics.Close())
95-
return err
95+
err := s.topic.Close()
96+
return errors.Join(err, s.metrics.Close())
9697
}
9798

9899
// SetVerifier set given verification func as Header PubSub topic validator

0 commit comments

Comments
 (0)