@socket.write, @socket.close, connected?, and creating @socket are locked with the
same mutex.
This patch locks them with the same mutex.
Otherwise, IOError may occur on highly traffic and CPU weak environment.
def send_packet(data)
# Raise exception if we aren't connected
raise MQTT::NotConnectedException unless connected? ## connected? is not locked with mutex
# Only allow one thread to write to socket at a time
@write_semaphore.synchronize do
@socket.write(data.to_s) ## connected? is not protected and `@socket.write` causes IOError.
end
end
@socket.write
,@socket.close
,connected?
, and creating@socket
are locked with the same mutex. This patch locks them with the same mutex.Otherwise,
IOError
may occur on highly traffic and CPU weak environment.Signed-off-by: Hiroshi Hatake cosmo0920.oucc@gmail.com