njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

put "disconnect" inside an "ensure" block #73

Closed syoder closed 8 years ago

syoder commented 8 years ago

Also includes a spec for this behavior. This will cause the client to disconnect even in cases where the connect block raises an exception.

I was connecting my mqtt client inside a thread. In certain circumstances, I would kill that thread and later reconnect. I noticed that every time I did that the number of threads in my process would go up by one. It turned out to be the client's @read_thread that was left dangling. With this change, the @read_thread gets properly terminated.

njh commented 8 years ago

Good improvement, thanks!

syoder commented 8 years ago

Thanks for the quick response and merging! Any plans to release a new version to rubygems soon?

njh commented 8 years ago

I don't currently feel very confident about the reliability of the QoS 1 support in the ruby gem.

I have been hesitant about releasing because of that. What is your experience of it?

syoder commented 8 years ago

Funny you ask - I tried QoS level 1 and it didn't work the way I thought it would. I haven't done a lot of testing yet though. I'm using this with Amazon's IoT service and hadn't gotten to the bottom of whether it was their broker or the client.

But I'm still learning about MQTT, and I'm in the beginning stages of integrating it into my project. I'll keep this in mind as I go and see if I can figure anything out w/r/t QoS 1.