-
Notifications
You must be signed in to change notification settings - Fork 160
Closed
Labels
Description
In ibmiotf/application.py:377, _messagesLock is acquired only if publishing was successful (if result[0] == paho.MQTT_ERR_SUCCESS), but it is released irrespectively in the final: block. This results in:
File "C:\AgentWork\c2889035b7ac6605\.testenv\lib\site-packages\ibmiotf\device.py", line 307, in publishEvent
self._messagesLock.release()
RuntimeError: release unlocked lock
This can happen if the client is disconnected when a message is sent (in which case paho will return MQTT_ERR_NO_CONN).
- This seems to have been broken accidentally as a part of ff473ce
- A simple way to reproduce this is to manually call
.disconnect(), then callpublishEvent.
I'm not 100% sure which code _messagesLock should protect; I think the try-finally can be moved into the if statement, i.e.,
if result[0] == paho.MQTT_ERR_SUCCESS:
try:
self._messagesLock.acquire()
if result[1] in self._onPublishCallbacks:
# paho callback beat this thread so call callback inline now
del self._onPublishCallbacks[result[1]]
if on_publish is not None:
on_publish()
else:
# this thread beat paho callback so set up for call later
self._onPublishCallbacks[result[1]] = on_publish
finally:
self._messagesLock.release()
return True