awslabs / aws-c-mqtt

C99 implementation of the MQTT 3.1.1 specification.
Apache License 2.0
93 stars 30 forks source link

Fix reconnecting issues when it fails to process a message and when a packet is still pending. #310

Closed gqmelo closed 1 year ago

gqmelo commented 1 year ago

Description of changes:

When an error is encountered when processing a packet, the client is supposed to reconnect but that doesn't always happen correctly because of two issues:

  1. When a full packet is read (as opposed to completing a pending packet), the result from s_process_mqtt_packet was never checked, so the connection is not terminated as it should.
  2. The pending packet stored in connection->thread_data.pending_packet was not cleaned-up on shutdown, so if there was a disconnection while a packet was still pending, after reconnecting the client would try to resume the pending packet. This would eventually cause ping timeouts and more connection attempts until the number of bytes corresponding to the pending packet is fully read.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

bretambrose commented 1 year ago

This fixes valid issues, but the packet framing fix (https://github.com/awslabs/aws-c-mqtt/pull/311) will include a testability refactor that obsoletes this particular PR.