Comments (2)
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.
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)
- Observable.Delay throws PlatformNotSupportedException on Blazor WASM. HOT 3
- `Task.ToObservable` will always continue on `TaskScheduler.Current` instead of the current synchronization context. HOT 2
- Add examples for IntroToRx Disposables appendix
- Analyzer for usage guidelines HOT 1
- Update IntroToRx test chapter based on how we test Rx.NET itself
- Add concrete scenario for Subject Factory in IntroToRx
- Add BackOffRetry example in IntroToRx
- Fix sentence on IntroToRx book
- [Feature] GroupSequentialBy
- PageNotFoundError about https://www.reactiveui.net/slack HOT 2
- Referencing System.Reactive from a WinUI 3 app or library is causing XLS errors to display in VS while XAML files are open HOT 1
- Incorporate https://github.com/runceel/ReactiveProperty HOT 5
- Throttle breaks the observable chain while running on wasm in .net 8 HOT 5
- Issue with CancellationToken lifetime in Observable.Using (async version) HOT 1
- Window and Buffer operators omit items which are released immediately HOT 5
- Benchmarks don't run for .NET 6+
- TestScheduler WithAsync swallows all exceptions making all tests pass HOT 3
- Publish symbols for assemblies in this package HOT 1
- Union doesn't dispose enumerator for empty lists HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive.