Closed Kofemolka closed 2 years ago
@amenzhinsky do you accept pull requests? This one is pretty critical to us. I can create PR with fix next week.
Fixes-incorrect-D2C-properties-encoding.patch.gz
@amenzhinsky please find patch attached.
@Kofemolka sure, can you submit a pr?
Version: v0.7.0 Transport: MQTT
Minimal example to reproduce.
Please notice, that custom property contains space (' ') in both key and value. It is not forbidden by IoT Hub messaging contract (https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct). Attempt to send such message will result in infinite re-connect loop:
This happens because in (github.com/amenzhinsky/iothub@v0.7.0/iotdevice/transport/mqtt/mqtt.go), properties are being incorrectly encoded. Spaces are replaced with '+' char, which is a wildcard in MQTT protocol, and leads to immediate connection drop. Since D2C message was not sent, after re-connect library will attempt to push this message once again leading to another connection drop. Cycle repeats forever.
Incorrectly encoded topic looks like this:
devices/my_device/messages/events/te+st=to+st
While Python and C++ SDKs produce correctly encoded:devices/my_device/messages/events/te%20st=to%20st
Suggested fix is to use encoding library different from 'net/url' or replace '+' with "%20" on top of it.