Giter Site home page Giter Site logo

Comments (2)

akarnokd avatar akarnokd commented on July 19, 2024

BehaviorSubject is very special in that it promises to emit the stored value to the incoming observer before it relays future values. The trouble is, a concurrent BehaviorSubject::OnNext call can happen while a BehaviourSubject::Subscribe is ongoing. OnNext mustn't be called concurrently so the two method calls must be serialized, hence the emission under the lock.

This happened in our case as the subscription was cancelled before the Subscribe was even called

The IDisposable returned by the BehaviorSubject::Subscribe can't be disposed upfront as it does not exist until the method returns it. There must have been something else causing the deadlock. Could you please share more details about the relevant code of yours?

from reactive.

Joost-Jens-Luminis avatar Joost-Jens-Luminis commented on July 19, 2024

Thank you for your quick reply, it's much appreciated.

Thinking about it, I agree that the Dispose couldn't cause the deadlock, except for when a subscribe causes a dispose of a previous subscription (but why should it?). I must have been confused as several dispose calls were waiting to get the lock and in the stacktrace that was always as a result of an Subscribe call. This was on Android though which may have caused issues in the stacktrace.

To be honest, there were a bunch of issues happening at the same time divided over several threads (up to 15 according to the parallel stacks window) which caused problems, making it difficult to separate which calls exactly caused the deadlock. (It took me a week and half to figure it all out)
I do know that the dispose was involved and making this change solved the deadlock for us. :)

As for what emits when; if the promise that the stored value is first emitted before any OnNext calls is sacred, then I agree my suggested change can't be made, even though it is unlikely an incoming OnNext call is emiting before the Subscribe completes. But if you believe it can happen (and I do think it can in theory), then by extension, there is no guarantee that all OnNext calls are emitted in the order they are received, which sort of makes the promise a bit of a weird one to make (what is the point of it).

I just wanted to put my issue and solution out here, as for us it works (and it may help other people). I do think it's clear a deadlock "could" happen there. But if my solution doesn't fit in the context of what the BehaviorSubject promises (or should promise) then feel free to close this issue.

Once again, I appreciate your quick response. Thanks again.

from reactive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.