Skip to content

Classes such as BehaviorSubject are at risk of deadlock, and there are issues with how locks are used. #2717

Description

@CloudlessMoon

For example, BehaviorSubject, as shown in the code below:

Image

The observer.on(.next(element)) operation is executed in the performLocked block. If the onNext block of the business logic contains serialQueue sync, there is a high risk of deadlock. For example, consider the following code:

Image

observer.on(.next(element)) should execute after unlock. I think that the lock/unlock block should only contain internal logic, and business logic should not be included within the lock/unlock block.

It should be so, pseudocode:
Image

Reproducible Demo: RxSwiftTest.zip

Running the demo can reproduce this problem. If it's not reproduced, you need to retries a few times; usually, it can be reproduced in 1-5 tries. In the demo, after a deadlock, ---rx end not all output. In Combine, the same code will always all output ---combine end.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions