Threading issues even with createThreadSafeStore
See original GitHub issueHi there! Recently began using this library, and have noticed some hard-to-reproduce errors popping up while developing. The errors occur inconsistently and mention threading issues:
You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://www.reduxkotlin.org/api/store#subscribelistener-storesubscriber for more details. You may be seeing this due accessing the store from multiplethreads. Try createThreadSafeStore() https://reduxkotlin.org/introduction/threading
and
You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store. You may be accessing getState while dispatching from another thread. Try createThreadSafeStore(). https://reduxkotlin.org/introduction/threading
However we do use createThreadSafeStore
, and these errors are being thrown from code outside our reducers (in thunks and views), so I am surprised to see these errors.
We are using:
org.reduxkotlin:redux-kotlin-threadsafe:0.5.5
org.reduxkotlin:reselect:0.5.5
org.reduxkotlin:redux-kotlin-thunk:0.5.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Redux on Multithreaded Platforms - PatrickJackson.dev
Given Javascript is single threaded its just not an issue. Working in JVM or Native suddenly presents a new set of challenges.
Read more >Redux on Multi-threaded Platforms - ReduxKotlin
Redux in multi-threaded environments brings additional concerns that are not present in redux for Javascript. Javascript is single threaded, so Redux.js did not ......
Read more >"Thread safety" in Redux? - Stack Overflow
It's not real threads, just for the lack of better wording. Actions are asynchronous and state keys are being accessed by reference. –...
Read more >Redux - Kotlinlang
Hey y all wave ran into some build issues e… ... a thread-safe store • recommended way to create the store is now...
Read more >How To Resolve Multi-Threading Problems - Digikey
How to Resolve Multi-Threading Problems in Concurrent C Applications ... OS lets many other threads run before thread zero even finishes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey there! I’m investigating this issue with @zackls and after some debugging, we think that the cause for this error may be related to the
createThreadSafeStore
implementation and wanted to run that by you guys. For context, we were also using theredux-kotlin-thunk
middleware, and our store implementation looked like:With this implementation, it seems like middlewares are applied to enhance the store’s dispatch function before the store’s functions get synchronized. For us, this meant that our thunks were accessing a non-synchronized dispatch function, whereas outside of thunks, invocations to dispatch were synchronized. Since our application makes use of multiple threads and some invocations to dispatch were not synchronized, we were seeing the reported error indicating that we weren’t using
createThreadSafeStore
.We solved this in our application by creating a new store enhancer to handle synchronization, and ordering it so that store creation / synchronization happens before middlewares are applied. Something like:
Happy to open a PR or discuss further if that all checks out!
PR looks good. I requested a small rename change. Hope to have it merged this week.