wolfSSL / wolfMQTT

wolfMQTT is a small, fast, portable MQTT client implementation, including support for TLS 1.3.
https://www.wolfssl.com
GNU General Public License v2.0
521 stars 155 forks source link

WMQTT_NET_GLUE Error: Skt Timeout, occurred in func: WMQTT_NETGlue_DoRead, line: 522 #296

Closed Elpra-Bozas closed 2 years ago

Elpra-Bozas commented 2 years ago

Hello,

We are seeing the following error and trying to understand where it is coming from. Could you please elaborate as to when the "WMQTT_NET_GLUE Error: Skt Timeout, occurred in func: WMQTT_NETGlue_DoRead, line: 522" will be given by wolfMQTT? The connection is good and stable, the system we are working on is a Microchip Harmony 3 PIC32MZ client along with PC/Server based Broker.

17:49:42.322 -> WMQTT_NET_GLUE Info: Started Connect 17:49:43.303 -> WMQTT_NET_GLUE Info: Connected Successfully 17:49:43.303 -> MQTT Task - run message: MqttClient_NetConnect, res: 0 17:49:43.303 -> MQTT Task - run message: MqttClient_Connect, res: 0 17:49:43.303 -> MQTT Task - Connect Ack: Return Code 0, Session Present No 17:49:45.358 -> MQTT Task - Subscribed Topic l9/0491625DA6C8/cmd/#, Qos 1 17:49:45.358 -> MQTT Task - Subscribed Topic l9/0491625DA6C8/cfg/#, Qos 1 17:49:48.381 -> MQTT Task - run message: MqttClient_Publish, res: 0 17:49:48.381 -> MQTT Task - Published Topic: l9/0491625DA6C8/sts/png 17:49:51.406 -> WMQTT_NET_GLUE Error: Skt Timeout, occurred in func: WMQTT_NETGlue_DoRead, line: 522, 17:49:51.406 -> MQTT Task - Client: 625DA6C87E345697, Disconnect error: -7 17:49:51.406 -> MQTT Task - run message: MqttClient_WaitMessage error, res: -7 17:49:51.406 -> MQTT Task - MQTT cycle Failed in state: 2, error code: -7! 17:49:51.406 -> MQTT Task - Client Start: QoS 1, broker 192.168.0.214 17:49:51.406 -> MQTT Task - run message: WMQTT_NETGlue_Initialize, res: 0 17:49:51.406 -> MQTT Task - run message: MqttClient_Init, res: 0 17:49:51.406 -> MQTT Task - run message: MqttClient_SetDisconnectCallback, res: 0 17:49:51.406 -> WMQTT_NET_GLUE Info: Started Connect 17:49:51.406 -> WMQTT_NET_GLUE Info: Connected Successfully 17:49:51.406 -> MQTT Task - run message: MqttClient_NetConnect, res: 0 17:49:51.406 -> MQTT Task - run message: MqttClient_Connect, res: 0 17:49:51.406 -> MQTT Task - Connect Ack: Return Code 0, Session Present Yes 17:49:55.357 -> MQTT Task - Subscribed Topic l9/0491625DA6C8/cmd/#, Qos 1 17:49:55.357 -> MQTT Task - Subscribed Topic l9/0491625DA6C8/cfg/#, Qos 1 17:50:00.339 -> MQTT Task - run message: MqttClient_Publish, res: 0 17:50:00.385 -> MQTT Task - Published Topic: l9/0491625DA6C8/sts/png 17:50:03.423 -> WMQTT_NET_GLUE Error: Skt Timeout, occurred in func: WMQTT_NETGlue_DoRead, line: 522, ...

embhorn commented 2 years ago

Hi @Elpra-Bozas

The WMQTT_NET_GLUE layer was developed by Microchip to plug into the wolfMQTT network abstraction. It looks like the publish is failing, which could cause the broker to drop the client connection. It also could have been caused by the previous subscribe (the subscribe ack is either not happening or not being printed in the log).

Elpra-Bozas commented 2 years ago

Hi embhorn,

it proves that this read socket timeout error is triggered when after subscribing or publishing, we stay in a state calling MqttClient_WaitMessage function (with a timeout of 30 seconds). This read socket timeout remains for a couple of minutes and then everything works smoothly.

If we omit this transition to the WAIT_FOR_MSG state where we call the wait message interface function and sustain our publishes, then we don't see anything wrong.

Is there a limitation on this state machine transition?

embhorn commented 2 years ago

You should call "wait message" when you wish for the application to receive an incoming publish message from the broker: https://github.com/wolfSSL/wolfMQTT/blob/8c3cd09326fe8ef502f408bdf3b958d59332b184/examples/nbclient/nbclient.c#L467

If it times out, you should call again, or possibly send a ping if the keep alive would expire.

embhorn commented 2 years ago

Hi @Elpra-Bozas

Are there any further questions? Can I mark this issue as resolved?

embhorn commented 2 years ago

Since we never heard back, I'll close this issue. Please feel free to reopen with more details or send an email to support@wolfssl.com