-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
AsyncStorage not fulfilling promise on Android 7+ #14101
Comments
@jsdario any updates on this? were you able to work around or resolve the problem? |
I was not able to fix it, but I cooked a heavy and chunky workaround. I simply reimplemented the AsyncStarage API around https://github.com/itinance/react-native-fs so we could use it as storage in Here it is the package https://github.com/netbeast/redux-persist-react-native-fs @dinzo If I learn any more I'll share it. I have to say that we are using a set of advanced Android build tools, which might be the reason. The problem still exists on react-native 0.44 and 0.45. |
I'm seeing this too. The promise returned by |
Can confirm that I'm seeing this too. After doing a few bundle reloads, I start getting the |
This comment has been minimized.
This comment has been minimized.
After further investigation: in my case I had an AsyncTask in some Java code (a local web server in my case) that was blocking and hence blocking other AsyncTasks (which AsyncStorage relies on). Setting my AsyncTask to execute in parallel to other tasks (via |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I submitted a Pull Request with the proposed solution by @RickDT, so far it is working for me. |
Thanks @jsdario . One hack that may work is something like this:
Because it only seems to be happening sporadically, hitting it multiple times may give you a better chance of one of them resolving. I know, this is very ugly 🥇 |
@jsdario waiting to merge your PR :) Thanks 👍 |
How not? I am using it in production, can you further describe the issue @allmaxgit ? |
I'm having this problem too. First time I execute the app code, AsyncStorage works fine, after few calls (4-5), getItem never call promise resolve function. |
Might work once after freshly rebooting device. I have to find an alternative AsyncStorage doesn't work for me, which sucks because saving things on device is so important. ?FIXED But |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@julestruong I face this issue on Ubuntu on ejected project. Expo project is fine, projects on Windows also doesn't have any issues. |
Faced the same issue on emulator android 7 and device with android 7. hm... @RickDT where should I inject you code with myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) I dont make any other async task hm... |
@Fortidude it will probably be in a 3rd party dependency, like an npm module that uses native Java code. Or Java code that you've introduced into the project. |
One way to solve this for now is to have a completely separate interface for the development environment's storage where the async storage fails to function. That's what I did – I got tired of figuring on solving the problem so I wrote a simple wrapper for the storage. The storage uses idb when the app is run in the development mode and the AsyncStorage if the remote debugger is disabled or running in production mode. Feel free to use the wrapper I wrote (available on https://gitlab.com/snippets/1690090). I haven't had a single problem with the storage ever since I enabled this on my most recent RN project. The only downside is that Reactotron fails to show the storage contents automatically since AsyncStorage isn't used. |
How is progress on this issue? I'm seeing the same error on removing multiple keys and waiting with promise.all, it just never resolves |
This comment has been minimized.
This comment has been minimized.
@aMarCruz you are right |
This comment has been minimized.
This comment has been minimized.
@xiaoyu311 You are 100% wrong. AsyncStorage uses an SQLite DB under the hood which doesn't require any permission. |
I went back to a 6.0 emulator and still found the same issue. So this is not just a 7+ problem |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Is this actually genuinely broken in RN core, and has been since May 2017, and the only solution is to use a third party library that replaces it? |
@jsdevel I would say yes. It might take a long time to recover the credibility of this API again for the existing developers, I guess. |
This comment has been minimized.
This comment has been minimized.
I'm seeing this issue on RN |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For those following along, #18522 has been approved and we're working on getting it merged. |
Summary: This patch is a bit of a hack job, but I'd argue it's necessary to dramatically improve the dev UX on Android devices. Somewhere in react-native, there's a shared SerialExecutor which AsyncStorage uses that is getting blocked, causing remote debugging to occasionally hang indefinitely for folks making AsyncStorage requests. This is frustrating from a dev UX perspective, and has persisted across several versions as far back as RN 0.44, and still remains on RN 0.54. The issue seems to only happen on Android > 7+, which is likely because the ThreadPoolExecutor behavior changed in this version: https://stackoverflow.com/questions/9654148/android-asynctask-threads-limits Fixes facebook#14101 We've been using this patch in production for the past 4 months on our team by overriding the AsyncStorage native module. We use AsyncStorage extensively for offline data and caching. You can test by compiling this commit version into a test react native repository that is set to build from source: ```sh git clone https://github.com/dannycochran/react-native rnAsyncStorage cd rnAsyncStorage git checkout asyncStorage cd .. git clone https://github.com/dannycochran/asyncStorageTest yarn install cp -r ../rnAsyncStorage node_modules/react-native react-native run-android ``` No documentation change is required. facebook#16905 [Android] [BUGFIX] [AsyncStorage] - Fix AsyncStorage causing remote debugger to hang indefinitely. Closes facebook#18522 Differential Revision: D8624088 fbshipit-source-id: 2a599fbca270a4826063cd93be8eaf796f34f57a
Summary: This patch is a bit of a hack job, but I'd argue it's necessary to dramatically improve the dev UX on Android devices. Somewhere in react-native, there's a shared SerialExecutor which AsyncStorage uses that is getting blocked, causing remote debugging to occasionally hang indefinitely for folks making AsyncStorage requests. This is frustrating from a dev UX perspective, and has persisted across several versions as far back as RN 0.44, and still remains on RN 0.54. The issue seems to only happen on Android > 7+, which is likely because the ThreadPoolExecutor behavior changed in this version: https://stackoverflow.com/questions/9654148/android-asynctask-threads-limits Fixes facebook#14101 We've been using this patch in production for the past 4 months on our team by overriding the AsyncStorage native module. We use AsyncStorage extensively for offline data and caching. You can test by compiling this commit version into a test react native repository that is set to build from source: ```sh git clone https://github.com/dannycochran/react-native rnAsyncStorage cd rnAsyncStorage git checkout asyncStorage cd .. git clone https://github.com/dannycochran/asyncStorageTest yarn install cp -r ../rnAsyncStorage node_modules/react-native react-native run-android ``` No documentation change is required. facebook#16905 [Android] [BUGFIX] [AsyncStorage] - Fix AsyncStorage causing remote debugger to hang indefinitely. Pull Request resolved: facebook#18522 Differential Revision: D8624088 Pulled By: hramos fbshipit-source-id: a1d2e3458d98467845cb34ac73f2aafaaa15ace2
Summary: This patch is a bit of a hack job, but I'd argue it's necessary to dramatically improve the dev UX on Android devices. Somewhere in react-native, there's a shared SerialExecutor which AsyncStorage uses that is getting blocked, causing remote debugging to occasionally hang indefinitely for folks making AsyncStorage requests. This is frustrating from a dev UX perspective, and has persisted across several versions as far back as RN 0.44, and still remains on RN 0.54. The issue seems to only happen on Android > 7+, which is likely because the ThreadPoolExecutor behavior changed in this version: https://stackoverflow.com/questions/9654148/android-asynctask-threads-limits Fixes facebook#14101 We've been using this patch in production for the past 4 months on our team by overriding the AsyncStorage native module. We use AsyncStorage extensively for offline data and caching. You can test by compiling this commit version into a test react native repository that is set to build from source: ```sh git clone https://github.com/dannycochran/react-native rnAsyncStorage cd rnAsyncStorage git checkout asyncStorage cd .. git clone https://github.com/dannycochran/asyncStorageTest yarn install cp -r ../rnAsyncStorage node_modules/react-native react-native run-android ``` No documentation change is required. facebook#16905 [Android] [BUGFIX] [AsyncStorage] - Fix AsyncStorage causing remote debugger to hang indefinitely. Pull Request resolved: facebook#18522 Differential Revision: D8624088 Pulled By: hramos fbshipit-source-id: a1d2e3458d98467845cb34ac73f2aafaaa15ace2
Issue
I am using
redux-persist
in a react native project, that runs just fine in a broad number of devices execept Android 7. I am trying to debug the problem on why my AsyncStorage is nor persisting and found this:The following code executes inside React Native component lifecycle's
Code after 'Inside setInterval' is never called. It only runs once if outside the setInterval. If I call once the code outside the setInterval it appears to run just fine. I also tried callback format vs async / await version but it does not seem to matter.
Same problem I had using firebase js library (callbacks never return after the first one). I am now looking for alternatives to workaround the problem.
Works with
setImmediate
andInteractionManager.runAfterInteractions
. Seems thatredux-persist
usessetImmediate
or fallsback tosetTimeout
.Any ideas?
Additional Information
In case this is a user level question I opened a question on stackoverflow, no luck yet, https://stackoverflow.com/questions/44114061/asyncstorage-is-not-returning-the-callback?noredirect=1#comment75248695_44114061
The text was updated successfully, but these errors were encountered: