Skip to content

Messages published out-of-order after reconnecting #731

@janvinas

Description

@janvinas

I've made this sample program to test what happens when the publisher loses and recovers connection:

package main

import (
	"fmt"
	"strconv"
	"time"

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

func main() {
	opts := mqtt.NewClientOptions().
		AddBroker("127.0.1.1:1883").
		SetOrderMatters(true).
		SetAutoReconnect(true).
		SetClientID("sender").
		SetCleanSession(false)

	client := mqtt.NewClient(opts)

	if token := client.Connect(); token.Wait() && token.Error() != nil {
		panic(token.Error())
	}

	i := 0

	for {
		client.Publish("test", 1, false, strconv.Itoa(i))
		i++
		time.Sleep(1 * time.Second)
	}
}

I start the program and then I block outbound traffic with:

iptables -A OUTPUT -p tcp --dport 1883 -d 127.0.1.1 -j DROP

When the connection is recovered (I remove the iptables rule), the messages are sent out of order, even though SetOrderMatters is true: (capture from the loopback interface)
Image

Is this intended behaviour? How can I make sure packets are sent in order? I want them to arrive in order at the subscriber.

Thanks,
Jan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssue could be resolved by improving the documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions