What's the maximum MQTT topic that can be subscribed? Error when trying to subscribe too many topics in one shot

I would like to find out if there’s a limit to the MQTT topic subscription? As I noticed there’s an error when trying to subscribe too many topics in one SUBSCRIBE request

Below is a snapshot of import keys data from the CloudWatch AWSIotLogsV2

eventType	Subscribe
logLevel	ERROR
protocol	MQTT
status	Failure
topicName	(total 13 topics, topic string length is about 619 characters including forward slashes in the topic)

Secondly, when there’s error, following logs is thrown in the console in a repeating loop. May I know what’s the proper way to handle the error, as it seems running forever.

[ERROR] [main] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-1.
[ERROR] [main] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [main] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[ERROR] [main] [openssl_posix.c:815] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.
[ERROR] [main] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-1.
[ERROR] [main] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [main] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[ERROR] [main] [openssl_posix.c:815] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.

Is the limit just the size of the buffer used to create the subscribe message on the device?

Found the AWS IoT limitation doc.
so it’s 8 per SUBSCRIBE request, and maximum 50 subscriptions per connection.

https://docs.aws.amazon.com/general/latest/gr/iot-core.html#iot-protocol-limits

May I know what’s the proper way to handle for error like this? Is this possible to finally discard the troubled received packet than letting it continue to loop on the error forever?

Currently it’s simply handled like this.

    while (true)
    {
        mqttStatus = MQTT_ProcessLoop(&mqttContext, processLoopTimeoutMs);
        if ((mqttStatus == MQTTSuccess) &&
            (mqttContext.connectStatus == MQTTConnected))
        {
        }
        else
        {
            /** @todo handle failure in connection */
            LogWarn(("Error in MQTT_ProcessLoop [STATUS=%d]", mqttStatus));
        }
    }

Error from console

[ERROR] [main] [openssl_posix.c:815] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.
[ERROR] [main] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-1.
[ERROR] [main] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [main] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[WARN] [main] [vc_mqtt_agent.c:232] Error in MQTT_ProcessLoop [STATUS=4]
[ERROR] [main] [openssl_posix.c:815] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.
[ERROR] [main] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-1.
[ERROR] [main] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [main] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[WARN] [main] [vc_mqtt_agent.c:232] Error in MQTT_ProcessLoop [STATUS=4]
[ERROR] [main] [openssl_posix.c:815] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.
[ERROR] [main] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-1.
[ERROR] [main] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [main] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[WARN] [main] [vc_mqtt_agent.c:232] Error in MQTT_ProcessLoop [STATUS=4]

Hello @iwt ,

As per coreMQTT documentation here, you should disconnect the MQTT connection followed by the transport layer connection and try to reestablish transport and MQTT connection again.
Usually Send or Recv failures as well as Keep Alive failure indicate that underlying transport connection has gone down, so the best practice is what I described above. In your case about SSL Read failed clearly indicates that the connection to the broker has failed.
Please let us know if you have any more questions.

1 Like