paho.mqtt.embedded-c icon indicating copy to clipboard operation
paho.mqtt.embedded-c copied to clipboard

keepalive failed by calling MQTTYield with short timeout and short interval.

Open aiot-embedded opened this issue 2 years ago • 5 comments

Hi,

In case of expiring last_receive timer, calling MQTTYield with short timeout and short interval will session close.

test code is as below.

void testcode(const char *topic, const char *payload)
{
  MQTTClient c=DefaultClient;
  MyMQTTClientInitialize(&c);

  MQTTPacket_connectData con = MQTTPacket_connectData_initializer;
  conData.keepAliveInterval = 60;
  MQTTConnect(&c,&con);

  message.qos       = QOS0;
  message.payload   = payload;
  message.payloadlen= strlen(payload);
  MQTTPublish(&c, topic, &message);

  sleep(60); //(1)

  MQTTYield(&c, 10); // (2)
  MQTTYield(&c, 10); // (3)
}

(1)

  • Expire last_sent and last_receive timer in this sleep() for TEST.

(2) First MQTTYield call

  • Send PINGREQ due to both of last_sent and last_receive timer has expired.
  • But only last_sent timer is reseted.

(3) Second MQTTYield call

  • PINGRESP is not coming yet and readPacket() return with timeout. (but it will come soon.)
  • In keepalive(), last_receive timer has remain expired and ping_outstanding is1 so keepalive() return FAILURE and session will closed.

Client should wait more time to receive PINGRESP. So, after sending PINGREQ client should also reset last_receive timer.

Thank you.

aiot-embedded avatar Dec 13 '22 00:12 aiot-embedded