MQTT disconnection because of mbedtls_ssl_read error

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ClMa_3563786
Level 2
Level 2

Hello,

Every around 10 hours, I have some MQTT disconnection. I've enabled logs to understand what was happening. Here the log:

TLS library asked for [5] bytes

Received new TCP packet with length [31]

TLS library asked for [26] bytes

Skip [5] no of bytes from TCP received packet with length : [31]

check if multiple TLS records present in single TCP pkt

TLS library asked for [5] bytes

Skip [31] no of bytes from TCP received packet with length : [31]

wiced_packet_get_data failed with result : [27]

[MQTT-LIB] Available TCP Wrapper Packet( available:2 frag:2 )

[MQTT-LIB] Received New MQTT frame (size: 2 type:13)

[MQTT-LIB] Received packet consumed SUCCESS

TLS library asked for [5] bytes

Received new TCP packet with length [31]

TLS library asked for [26] bytes

Skip [5] no of bytes from TCP received packet with length : [31]

check if multiple TLS records present in single TCP pkt

TLS library asked for [5] bytes

Skip [31] no of bytes from TCP received packet with length : [31]

wiced_packet_get_data failed with result : [27]

[MQTT-LIB] Available TCP Wrapper Packet( available:2 frag:2 )

[MQTT-LIB] Received New MQTT frame (size: 2 type:13)

[MQTT-LIB] Received packet consumed SUCCESS

TLS library asked for [5] bytes

Received new TCP packet with length [31]

TLS library asked for [26] bytes

Skip [5] no of bytes from TCP received packet with length : [31]

mbedtls_ssl_read failed with error : [-30848]

[MQTT-LIB] TCP receive error

[MQTT-LIB] Received Packet ERROR

I didn't find in the code the define that match to this error.
Would it be possible to get more clues on this ?

Thanks

0 Likes
3 Replies
ClMa_3563786
Level 2
Level 2

I found the define:

#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY             -0x7880  /**< The peer notified us that the connection is going to be closed. */

And the error 27 when calling the function wiced_packet_get_data() is:

RESULT_ENUM( prefix, CORRUPT_PACKET_BUFFER,     27 ),   /**< Packet buffer is corrupted */ \

Do you know why theses errors happen ?

Thanks

0 Likes

Hello,

The error is because the peer has notified to close the connection.

The code flow is:

mqtt_process_tcp_receive() -> wiced_tcp_receive() -> wiced_tls_receive_packet() -> mbedtls_ssl_read()

The mbedtls_ssl_read() is returning

#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY                 -0x7880  /**< The peer notified us that the connection is going to be closed. */

The MQTT lib shows it just as a TCP connection error but not the reason for connection. You can try to inittiate another connection when you receive a CLOSE_NOTIFY error.

Hello,

Thanks for the answer. I'm already reconnecting but I'm surprised to get so many disconnections.

Using a raspberryPi or an ESP32 devices with the same conditions (WiFi network, same physical location, MQTT broker, keep_alive setting, ...), I have much much less disconnection (4 time less disconnections).

Could it be a thread priority or something else ?
Have you done some test to validate the stability of the MQTT connection ?


Thanks

0 Likes