Skip to content

Commit

Permalink
ensure correct order of Stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Dec 12, 2024
1 parent 5ece33e commit fee9aac
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions p2p/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ func (s *Subscriber[H]) Start(context.Context) (err error) {
}

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

err := s.topic.Close()
return errors.Join(err, s.metrics.Close())
func (s *Subscriber[H]) Stop(context.Context) (err error) {
err = errors.Join(err, s.metrics.Close())
// we must close the topic first and then unregister the validator
// this ensures we never get a message after the validator is unregistered
err = errors.Join(err, s.topic.Close())
err = errors.Join(err, s.pubsub.UnregisterTopicValidator(s.pubsubTopicID))
return err
}

// SetVerifier set given verification func as Header PubSub topic validator.
Expand Down

0 comments on commit fee9aac

Please sign in to comment.