Skip to content

bug: publish messages without being subscribed #1207

@richard-ramos

Description

@richard-ramos

As described in status-im/status-go#5759 (comment) by @igor-sirotin
The code as it is right now would allow publishing a message while not being subscribed to a pubsub topic.

I suggest either checking if a subscription to the pubsub topic before publishing and return an error or maybe attempt to subscribe with this code. I kinda prefer to return an error instead since then the user of the library can choose to subscribe or not depending on the error (and also because publishing without being subscribed does look like an incorrect usage of gowaku)

//Check if gossipsub subscription already exists for pubSubTopic
		if !w.IsSubscribed(pubSubTopic) {
			_, err := w.subscribeToPubsubTopic(cFilter.PubsubTopic)
			if err != nil {
				//TODO: Handle partial errors.
				w.log.Error("failed to subscribe to pubsubTopic", zap.Error(err), zap.String("pubsubTopic", cFilter.PubsubTopic))
				return nil, err
			}
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions