question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible issue with certain Observables

See original GitHub issue

An issue appeared with the Bluetooth package RxAndroidBle that might be of interest. The authors have deprecated their own ConnectionSharingAdapter for sharing BLE connections, and now recommend the use of RxReplayingShare. This is my understanding:

The package has a method Observable<RxBleConnection> establishConnection( ... ). This Observable is somewhat unusual in that it emits a single item (the connection), and never completes. Unsubscribing from it terminates the connection, and if the connection is lost due to a Bluetooth fault, the subscription is canceled with an onError() exception.

Apparently the issue is that RxReplayingShare will continue to emit the “stale” cached connection to subscribers even after the original connection is broken. According to the OP, the problem is that ReplayingShare does not react to finalizations. He describes a fix that might be worth considering. Comments appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
streetsofbostoncommented, Apr 8, 2018

I found this issue when using it with RxAndroidBle, where the RxBleConnection becomes invalid after the Observable that emits it is finalized. I agree with you @JakeWharton that always clearing the cached value of the ReplayingShare on finalization may not be a good idea. Doing this fixes the RxBleConnection issue, but may not be a good general solution.

I created a new class ReplayingUnfinalizedShare that does clear the cached value on finalization of the shared stream and it fixes the RxBleConnection issues we found (still, there are race-conditions that I would need to address).

For a solution we could have variations of the ReplayingShare, like the ReplayingUnfinalizedShare, that clear the cached value each in a unique way. Let me know if it is worth doing this and I could open an issue/PR on your repo.

1reaction
PaulWoitaschekcommented, May 31, 2018

This is the pitfall I fell into:

  @Test
  fun doesNotHoldOldValueAfterDisposed() {
    val subject = BehaviorSubject.create<String>()
    val observable = subject.compose(ReplayingShare.instance())

    val observer = observable.test()
    subject.onNext("Foo")
    observer.dispose()

    subject.onNext("Bar")

    observable.test()
        .assertNever("Foo")
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Common Rxjs Pitfalls (and how to avoid them)
In this post, we will go over some common trouble situations, explain why the situation occurs and how to fix it. If you...
Read more >
An intro to Observables and how they are different from ...
The answer is Promises, Observables, callbacks and many more. We know that these asynchronous operations return responses, either some data ...
Read more >
How to Avoid Observables in Angular - DEV Community ‍ ‍
In this section, we will get a good overview of some of the scenarios we get in touch with reactive programming in Angular....
Read more >
5 helpful RxJS solutions. to everyday problems | Compendium
Say our searchTerm$ observable is a ReplaySubject. It has not been provided a start value and combineLatest will not emit a value until...
Read more >
Observables
k=1 Ok/n in the limit where the number of measurements n → ∞. The possible outcomes of experiments, Ok, are the eigenvalues of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found