QTBUG-74279 resulted in change id I6d8e540f7e89c621e5c010669085882d25440b0a
The goal was to follow spec in that client side the connection should be closed upon not receiving a ping response.
The implementation depends on counting pings and responses.
The comment states:
" // Consider two pending PINGRESP as reasonable."
and then the QMqttConnection::sendControlPingRequest() code states:
m_pingTimeout > 1
When a client sets a keepalive, it will also send corresponding pings and then a single pending pingresp seems reasonable.
However, QMqttClient::requestPing() exists, allowing one to manually trigger a ping as well. Since QMqttClient doesn't allow informing the broker about a keepalive without sending automatic pings, any manually sent ping will be in addition to the automatically sent ones. Therefor, allowing only a single pending ping response causes 'unexpected client disconnects' by QMqttClient.
The usecase for sending manual pings is Android -> since the Qt process can be put asleep, one cannot trust the automatically sent pings to keep the connection alive. So we're triggering the manual pings periodically from the Android side, which caused QMqttClient to sometimes disconnect thinking it was missing ping responses.
When checking for "m_pingTimeout > 1" in QMqttConnection::sendControlPingRequest() maybe manually sent pings can be taken into account (i.e. the value 1 gets increased upon a manual ping and decreased upon a ping response with a minimum of 1 or something along that line).