Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Client.publishEvent releases _messagesLock even if not acquired #122

@mvdfugro

Description

@mvdfugro

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 call publishEvent.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions