Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock on Offline Shadow Update #52

Closed
kc9zyz opened this issue Jul 27, 2017 · 3 comments
Closed

Deadlock on Offline Shadow Update #52

kc9zyz opened this issue Jul 27, 2017 · 3 comments

Comments

@kc9zyz
Copy link

kc9zyz commented Jul 27, 2017

Preconditions:

  1. Two Device shadows are associated (as in a gateway scenerio), but no update has been sent so the update/accepted and update/rejected topics are not yet subscribed to.

Process to Re-Create:

  1. Remove connectivity from the library
  2. Attempt to update one of the shadows, receive a subscribeTimoutException
  3. Attempt to update the second shadow

Result

The call to update the second shadow never returns. The offending call is here:

def basicShadowSubscribe(self, srcShadowName, srcShadowAction, srcCallback):
        self._shadowSubUnsubOperationLock.acquire()
        currentShadowAction = _shadowAction(srcShadowName, srcShadowAction)
        if currentShadowAction.isDelta:
            self._mqttCoreHandler.subscribe(currentShadowAction.getTopicDelta(), 0, srcCallback)
        else:
            self._mqttCoreHandler.subscribe(currentShadowAction.getTopicAccept(), 0, srcCallback)
            self._mqttCoreHandler.subscribe(currentShadowAction.getTopicReject(), 0, srcCallback)
        time.sleep(2)
        self._shadowSubUnsubOperationLock.release()

On line 68 a lock is acquired. Notice that on lines 71, 73, and 74, a subscribeTimeoutException may be raised (as happened in the second step to recreate), jumping past the lock release call on line 76. Any cases of locks being acquired/released should be using context managers or exception handling to ensure that the lock is released if an operation fails.

@liuszeng
Copy link
Contributor

Hi @kc9zyz ,

Thank you very much for pointing this out! We will incorporate the bug fix into the next release.

Thanks,
Liusu

@liuszeng
Copy link
Contributor

liuszeng commented Sep 8, 2017

Addressed in release v1.2.0.

@liuszeng liuszeng closed this as completed Sep 8, 2017
@kc9zyz
Copy link
Author

kc9zyz commented Sep 8, 2017

@liuszeng Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants