Skip to content

Unsubscribe surprisingly breaks previous subscribe #336

@rollulus

Description

@rollulus

Subscribing to /a/# works correctly.
However, if one subscribes to /a/b/# and unsubscribes from it afterwards, the earlier message handler doesn't receive anything anymore, although the broker publishes according to tcpdump.

To reproduce:

package main

import (
	"log"
	"time"

	mqtt "github.com/eclipse/paho.mqtt.golang"
)

func msgHandler(_ mqtt.Client, m mqtt.Message) {
	log.Printf("received message for topic %s: %s", m.Topic(), string(m.Payload()))
}

func main() {
	o := mqtt.NewClientOptions().AddBroker("tcp://" + "iot.eclipse.org:1883")
	c := mqtt.NewClient(o)
	if t := c.Connect(); t.Wait() && t.Error() != nil {
		panic(t.Error())
	}

	if t := c.Subscribe("/a/#", 1, msgHandler); t.Wait() && t.Error() != nil {
		panic(t.Error())
	}

	if t := c.Subscribe("/a/b/#", 1, msgHandler); t.Wait() && t.Error() != nil {
		panic(t.Error())
	}

	if t := c.Unsubscribe("/a/b/#"); t.Wait() && t.Error() != nil {
		panic(t.Error())
	}

	time.Sleep(time.Hour)
}

And publish messages from the console with:

mosquitto_pub -h iot.eclipse.org -t '/a/b/hello'   -d -m 'xxxx' -q 1
mosquitto_pub -h iot.eclipse.org -t '/a/hello'   -d -m 'xxxx' -q 1

My expectation is to receive those messages. In practice, nothing happens.

To verify that the example isn't broken itself, remove the last Subscribe and Unsubscribe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions