espressif / esp-mqtt

ESP32 mqtt component
Apache License 2.0
603 stars 255 forks source link

CONNACK reading error (IDFGH-968) #113

Closed bojczmac closed 5 years ago

bojczmac commented 5 years ago

In function esp_mqtt_connect() after sending connect message you are trying to receive server response like this: read_len = transport_read(client->transport, (char *)client->mqtt_state.in_buffer, client->mqtt_state.outbound_message->length, client->config->network_timeout_ms); This assumption is really bad, because in slower network data can be received not in one pice. For example on TTN broker, this function reads only ONE byte. You shall read packet header, validate it and read info how many bytes must be read. Take a look for this pull request: https://github.com/espressif/esp-mqtt/pull/36

david-cermak commented 5 years ago

That's correct, the library can handle multiple messages in a buffer and reception of incomplete message, but the mqtt header needs to be received first, so it really is susceptible to this scenario.

Will be fixed. Thanks for raising this issue (and pointing out the PR)