BehaviorSubject concurrent subscription and sending is broken
See original GitHub issueBehaviorSubject should ensure that the last notification always reaches the subscriber. When the subscription and sending happens concurrently, there is a high probability that this property gets broken.
Test has been prepared that easily reproduces the error. https://gist.github.com/andrask/fc06abfd70daa6f91edb#file-behaviorsubjectsubscribeandsendconcurrently-java
The test involves two threads: 1) trying to subscribe 2) trying to send next. These are carefully coordinated to allow real concurrent execution. The test is that the subscriber must receive the sent value. The issue almost certainly happens in a few hundred retries.
Note that with a Thread.sleep(1)
the issue goes away.
Note that the test is something I distilled from what I saw in my production code. There may be little issues with it but the concurrency problem certainly exists as it is reproducibly just by stepping through the code.
Issue Analytics
- State:
- Created 9 years ago
- Comments:21 (12 by maintainers)
Subscription is not an on* method and therefore this is not expected.
On Tue, May 24, 2016 at 7:38 PM Artem Zinnatullin notifications@github.com wrote:
Seems that my idea of delaying the action in
doOnSubscribe
still doesn’t fix the issue. Now I’m thinking there’s something wrong betweenonNext
andonComplete
. Sometimes onlyonComplete
is received…