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

Crash when dispatching actions from inside StoreSubscriber.newState() #498

Open
gmorning opened this issue Dec 7, 2022 · 2 comments
Open

Comments

@gmorning
Copy link

gmorning commented Dec 7, 2022

Screenshot 2022-12-07 at 18 16 47

We have several actions that are chained one after another in this manner:

  1. Action is dispatched
  2. A StoreSubscriber receives newState callback on state change
  3. It dispatches another Action on the same Store
  4. Another StoreSubscriber (or maybe the same one) receives newState callback on state change
  5. It dispatches another Action on the same Store

These chains are not infinitely recursive, their depth is 2-4 actions. They all operate on single (main) thread synchronously. We see a crash when 2nd or 3rd dispatch is called inside ReSwift. It occurs with different action sequences. One case we can reproduce 100% in debug configuration (-Onone), but it's not reproduced in release configuration.

Stacktrace top is __swift_instantiateConcreteTypeFromMangledName

@mjarvis
Copy link
Member

mjarvis commented Dec 7, 2022

I recommend against this pattern -- It could be running into call-stack or memory-stack restrictions, due to not allowing the runloop to complete and reset.

If you need to, dispatching the chained actions should resolve the issue, as they'll occur on the next runloop and have the available resources again.

Better is to handle the state changes within the singular, first action. If its all synchronous, then technically there is no need for the follow-up actions. You can add the first action to the reducers appropriately.

@DivineDominion
Copy link
Contributor

@mjarvis This would be an example of (ab)using ReSwift as a general-purpose tool to decouple and implement messaging between components, something we brushed a couple of years ago, right?

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

3 participants