WIP: Fix notification unsubscribe lock#294
Open
Electro707 wants to merge 1 commit intopeplin:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here is a description of the cause of this pull request (I will be referring to the bgapi backend).
Description of issue:
When the
unsubscribefunction tries to unsubscribe from a certain notification, it locks a thread lock withwith self._lock. Theunsubscribefunction then calls a function which waits for a 'write confirmation' data packet from the Bluetooth client to confirm that the write to the notification configuration handler is successful. If a server is notifying the client at a fast enough pace, a notification packet will come it before the 'write confirmation' packet. That notification packet will then call the_receive_notificationfunction. That function can't run as the_locklock is locked up by thesubscribefunction. This results in a lockup, as the_receive_notificationfunction is trying to use a lock that is occupied and won't be released until thesubscribefunction receives a 'write confirmation' packet, which it can't as the packet handler is locked up by the_receive_notificationfunction.(Hopefully I got my point across and didn't create more confusion than before)
Fix:
A solution is to have the
_receive_notificationfunction check if either:_locklock is acquired by another function (What this PR currently does as of commit 60b7ed4)self._callbacksarray before thewith self._lockline is called.What is the best way to approach this issue (or if there is another better way to)?