Skip to content

Publish still send puback even if offline #401

@YannickRiou

Description

@YannickRiou

Describe the bug

Even after updating to awsiotsdk==1.3.1 and awscrt==0.6.1 (checked by using pip3 freeze), I still encouter the problem that was originally described at the beginning of this issue #62.

This is the way I call the publish in my main code:

   self.mqtt = MQTTHandler(self.config_aws)

            if(self.mqtt.connect() == False):
                logging.error(" Network is down for MQTT Push")
            else:
                for key in tmp_values:
                    logging.debug("Pushing key to aws : {}".format(tmp_values[key]))
                    try:
                        self.mqtt.publish(self.local_settings['TOPIC'], tmp_values[key])
                    except Exception as e:
                        logging.warning("MqttPushFailure {}".format(e))
                        continue
      
            try:
                self.mqtt.disconnect()
            except:
                logging.error("No MQTT connection to disconnect")

And this is what the self.mqtt.publish function contains (using the low level publish function from aws sdk) :

    def publish(self, topic, payload):
        """using the mqtt_connexion object, publish the input payload in the input topic. 

        Args:
            topic (String): MQTT Topic
            payload (dict)
        """
        message=json.dumps(payload)                
        logging.debug(" Publishing message to topic '{}': {}".format(topic, message))
        self.mqtt_connection.publish(
            topic=topic,
            payload=message,
            qos=mqtt.QoS.AT_LEAST_ONCE)

        time.sleep(1)

This way If I manually cut the network connection after the mqtt.connect(), I do get the info that the session is interrupted (via the on_connection_interrupted callback) but the publish doesn't throw any exception and just publish the messages without waiting.

Expected Behavior

Publish should throw an exception when network is offline so that we can send the message later.

Current Behavior

Publish just continue without throwing an exception.

Reproduction Steps

  • Connect to AWS MQTT
  • Cut the network connection
  • Publish a message to AWS MQTT

Possible Solution

v1.3.1 of awsiotsdk should resolve this (as long with awscrt 0.6.1)

Additional Information/Context

No response

SDK version used

1.3.1

Environment details (OS name and version, etc.)

Raspberry pi using python3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions