Open
Conversation
jpsoultanis
approved these changes
Feb 7, 2022
Contributor
jpsoultanis
left a comment
There was a problem hiding this comment.
Thanks for submitting a fix for this issue :)
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.
Expected behavior
Underlying peripheral queue should execute all operations in sequential manner.
The issue
Peripheral queue is not executing operations sequentially when there are more than 2 operations enqueued.
Receiving side would get interleaving chunks for different incoming packets.
Reason
public func queue<O: GattOperation>(operation: O) -> Single<O.Element>returns sequence with injected side-effects utilizing internal state to manage/run operation queue in case there are more operations to be executed.doFinallyrx extension was added to enqueue next operation when the current one finishes, however it's not implemented correctly.Rx lifecycle usually looking like this:
==...==completed==disposed=|
==...==error==disposed=|
Please note: subscription is disposed immediately after completed/error event occurs.
doFinallyis called twice per single operation (e.g. completed, disposed) and due to side-effects utilizing internal state it skips freshly enqueued operation (which will still complete!) and moves to the next one.Example:
Write1completesdoFinallyis executed forWrite1because of the completed event soWrite #2is enqueueddoFinallyis executed again forWrite1because subscription will be disposed soWrite #3will be enqueuedWrite2andWrite3simultaneouslyAdded test to cover this behavior. Revert my change to
doFinallyto see test failing with previous logic: receiving side would get "Packet 1 containing dummy dataPackeP3t 2 containing slightly more dummy data than first packet" instead of "Packet 1 containing dummy dataPacket 2 containing slightly more dummy data than first packetP3"Fix
Added variable to guard against multiple invocations.