Open stapelberg opened 3 years ago
Steps to reproduce:
hmq
mosquitto_sub -t '#'
package main
import ( "fmt" "log"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
func publishInvalid() error { opts := mqtt.NewClientOptions().AddBroker("tcp://localhost:1883") opts.SetClientID("dhcp4d") mqttClient := mqtt.NewClient(opts) if token := mqttClient.Connect(); token.Wait() && token.Error() != nil { return fmt.Errorf("MQTT connection failed: %v", token.Error()) }
token := mqttClient.Publish("foo/valid", 0, true /* retained */, []byte("payload")) token.Wait() token = mqttClient.Publish("foo/invalid/\xec\x8c\x04\x10\x27", 0, true /* retained */, []byte("payload")) token.Wait() return nil
}
func main() { if err := publishInvalid(); err != nil { log.Fatal(err) } }
Now, `mosquitto_sub` is in an infinite reconnect-loop, and hmq will print:
{"level":"info","timestamp":"2021-01-07T22:45:12.810+0100","logger":"broker","caller":"broker/broker.go:190","msg":"Start Listening client on ","hp":"0.0.0.0:1883"} {"level":"info","timestamp":"2021-01-07T22:45:13.853+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"dhcp4d"} {"level":"error","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"dhcp4d"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 2 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 2 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 3 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 3 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 4 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 4 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 5 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 5 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} ^C2021/01/07 22:45:22 signal received, broker closed. interrupt
As per https://github.com/mqttjs/mqtt-packet/issues/59, hmq should instead verify that topic names are valid utf-8, and close the connection when a client sends invalid utf-8.
@chowyu08 this issue can be closed
Steps to reproduce:
hmq
mosquitto_sub -t '#'
import ( "fmt" "log"
)
func publishInvalid() error { opts := mqtt.NewClientOptions().AddBroker("tcp://localhost:1883") opts.SetClientID("dhcp4d") mqttClient := mqtt.NewClient(opts) if token := mqttClient.Connect(); token.Wait() && token.Error() != nil { return fmt.Errorf("MQTT connection failed: %v", token.Error()) }
}
func main() { if err := publishInvalid(); err != nil { log.Fatal(err) } }
{"level":"info","timestamp":"2021-01-07T22:45:12.810+0100","logger":"broker","caller":"broker/broker.go:190","msg":"Start Listening client on ","hp":"0.0.0.0:1883"} {"level":"info","timestamp":"2021-01-07T22:45:13.853+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"dhcp4d"} {"level":"error","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:17.454+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"dhcp4d"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 2 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 2 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:18.455+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 3 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:19.457+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 3 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 4 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 4 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:20.458+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/broker.go:269","msg":"read connect from ","clientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 5 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"info","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:514","msg":"process retain message: ","packet":"SUBSCRIBE: dup: false qos: 1 retain: false rLength: 6 MessageID: 5 topics: [#]","ClientID":"mosq-jauBjjAjwJcc1Sy865"} {"level":"error","timestamp":"2021-01-07T22:45:21.459+0100","logger":"broker","caller":"broker/client.go:170","msg":"read packet error: ","error":"EOF","ClientID":"mosq-jauBjjAjwJcc1Sy865"} ^C2021/01/07 22:45:22 signal received, broker closed. interrupt