-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Describe the bug
A clear and concise description of what the bug is.
To reproduce
package main
import (
"context"
"fmt"
"log"
"net/url"
"github.com/eclipse/paho.golang/autopaho"
"github.com/eclipse/paho.golang/paho"
)
func main() {
broker, _ := url.Parse("mqtt://127.0.0.1:1883")
cm, err := autopaho.NewConnection(context.Background(), autopaho.ClientConfig{
ServerUrls: []*url.URL{broker},
ClientConfig: paho.ClientConfig{
ClientID: "client",
OnServerDisconnect: func(*paho.Disconnect) {
fmt.Println("OnServerDisconnect called")
},
},
ConnectPassword: []byte("foo"),
ConnectUsername: "foo",
PahoDebug: log.Default(),
PahoErrors: log.Default(),
})
if err != nil {
panic(err)
}
cm.AwaitConnection(context.Background())
select {}
}
Run the above client. In another window, run mosquitto_pub -V mqttv5 -t foo -m bar -i client
.
This should cause mosquitto to send a DISCONNECT packet with the bytes e0 1 8e
where 1 is the message length and 8e is reason code 142, "Session taken over". The OnServerDisconnect callback does not get called.
Expected behaviour
The OnServerDisconnect callback is called when the server sends a well-formed DISCONNECT packet.
Software used:
- Mosquitto 2.0.21.
- paho.golang v0.22.0
Additional context
The MQTT v5 Spec is a little bit vague about whether the property length must be included in a DISCONNECT packet. EMQX, for example, does include the length even when there are zero properties. However, my interpretation is that it is valid to omit it. In section 3.14.2.2.1, it states
If the Remaining Length is less than 2, a value of 0 is used.
In section 3.14.2.1, it uses very similar language to describe the default reason code:
If the Remaining Length is less than 1 the value of 0x00 (Normal disconnection) is used.
...and here, I know for a fact that it's valid to omit the reason code if it's 0x00 (and there are no properties). So, I extrapolate that when 3.14.2.2.1 states that a value of 0 is used, it means from the perspective of the one decoding the packet. All this to say, I think this is a bug in paho.golang and not mosquitto.