Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateChangeListener being called after unsubscribing [concurrency] #11

Open
dlemures opened this issue Jul 3, 2017 · 1 comment
Open
Milestone

Comments

@dlemures
Copy link

dlemures commented Jul 3, 2017

onStateChanged method from a StateChangeListener can be called after it has unsubscribe d.

Steps:

  1. We have a Store S and Listener L.
  2. In Thread 1, S starts notifying listeners using NotifySubscribersMiddleware .
  3. CopyOnWriteArrayList is used to keep the listeners. Therefore, we iterate using a copy of the list that won't be changed during the iterator loop.
  4. In Thread 2, L calls unsubscribe to unsubscribe from the Store S. This happens before step 3 is over and L is notified.
  5. S notifies L calling onStateChanged, even thought it is already unsubscribed.

The scenario looks difficult to reproduce, however the consequences can be fatal.

@stephanenicolas stephanenicolas modified the milestone: 1.1.1 Sep 7, 2017
@tmtron
Copy link

tmtron commented Nov 6, 2017

Is this the same as for Redux-store?

The subscriptions are snapshotted just before every dispatch() call. If you subscribe or unsubscribe while the listeners are being invoked, this will not have any effect on the dispatch() that is currently in progress. However, the next dispatch() call, whether nested or not, will use a more recent snapshot of the subscription list.

If so: how does Redux handle this issue? Or is it something that the users must just be aware of?

@alin-turcu alin-turcu modified the milestones: 1.1.1, 1.1.2 Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants