sskaje / mqtt

MQTT Client class
https://sskaje.me/category/MQTT/
MIT License
86 stars 33 forks source link

endless ping sent if pipe breaks #9

Closed dethegeek closed 8 years ago

dethegeek commented 8 years ago

Hi

The library keeps sending pings despite the connections has been closed

Here is the relevant backtrace, repeated again and again many times per second

  *** PHP Notice(8): fwrite(): send of 2 bytes failed with errno=32 Broken pipe
  Backtrace :
  :                                                  
  .../lib/mqtt/mqtt/SocketClient.php:166 fwrite()
  .../lib/mqtt/mqtt/MQTT.php:1230       sskaje\mqtt\SocketClient->write()
  .../lib/mqtt/mqtt/MQTT.php:1214       sskaje\mqtt\MQTT->message_write()
  .../lib/mqtt/mqtt/MQTT.php:1191       sskaje\mqtt\MQTT->simpleCommand()
  .../lib/mqtt/mqtt/MQTT.php:1175       sskaje\mqtt\MQTT->ping()
  .../lib/mqtt/mqtt/MQTT.php:1132       sskaje\mqtt\MQTT->keepalive()
  .../inc/mqttclient.class.php:97       sskaje\mqtt\MQTT->loop()

In sskaje\mqtt\MQTT->ping() there is no test on the actually written bytes, making the library unable to detect the broken pipe.

I guess the library will enter in an endless loop because no MesageHandler callback can run to unsubscribe all topics or close the connection.

Maybe sskaje\mqtt\MQTT->ping() should throw an exception here.

sskaje commented 8 years ago

Hi @dethegeek , please try the latest commit.

dethegeek commented 8 years ago

Hi

Thank you, this is exactly what I expected, especially the PINGRESP handler. I was thinking about this to self monitor my service.

I updated the library a few days ago and I noticed a better behavior of my service. No more hich CPU usage, but I may still observe some memory leaks. I'll think I'll definitely adopt your library for my project.