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
542 stars 135 forks source link

Avoid to close @socket of MQTT::Client unexpectedly #130

Open ashie opened 3 years ago

ashie commented 3 years ago

Since it is locked only when writing, it may be closed by anothre thread while reading or writing. In actual we often get the following error when we are processing massive messages by fluent-plugin-mqtt-io:

IOError,stream closed in another thread

This commit ensure to protect all atomic operations of the socket.

ashie commented 3 years ago

It's a revised patch of #129.

ashie commented 3 years ago

The patch can be simplified by using Thread::Mutex#owned? but I don't use it because it's breaks CI on Ruby 1.9.3.