React-native: AsyncStorage.getItem blocks when debugging remotely

Created on 9 Mar 2017  路  92Comments  路  Source: facebook/react-native

Description

In some situations when calling AsyncStorage.getItem, either with a callback, calling then or using async await, the proceeding callback is not called and the promise does not resolve. This only happens when the remote debugger is on.

result or error are not called below:
AsyncStorage.getItem('key') .then(result => console.log('result', result)) .catch(e => console.log('err', e));

AFTER is not printed (and no error is thrown):
console.log('BEFORE'); const result = await AsyncStorage.getItem('key'); console.log('AFTER');

The same code above completes the first time (and several consecutive times) it is run in the same debug session but blocks at a later stage. The point in time where it starts blocking is consistent in my app, so there is a piece of context that I haven't found yet which is causing it. I will continue searching for this context. Are maybe others running into similar behavior?

No matter the availability of data, getItem should always resolve (or reject), right?

Reproduction

I will keep trying to isolate the reproduction but so far I have not been able to cleanly reproduce, but in my full app, it is consistently occurring.

Solution

Additional Information

This issue is occurring on both iOS devices and simulators. I haven't seen it on Android yet.
OS X 10.11.6
Xcode 8.2.1
React Native Debugger 0.5.6
React Native 0.42.0

  "dependencies": {
    "react": "15.4.2",
    "react-native": "0.42.0",
    "analytics-react-native": "^1.0.1",
    "axios": "^0.11.1",
    "bugsnag-react-native": "^2.0.2",
    "firebase": "^3.6.10",
    "moment": "2.17.1",
    "react-native-auth0": "^1.0.0-beta.1",
    "react-native-code-push": "^1.17.2-beta",
    "react-native-drawer": "^2.2.3",
    "react-native-gifted-chat": "https://github.com/immidi/react-native-gifted-chat",
    "react-native-loading-spinner-overlay": "^0.4.1s",
    "react-native-lock": "git+ssh://[email protected]/auth0/react-native-lock.git",
    "react-native-navbar-wrapper": "^1.0.0",
    "react-native-onesignal": "^3.0.2",
    "react-native-smart-badge": "1.1.1",
    "react-navigation": "1.0.0-beta.3",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-devtools-extension": "^2.13.0"
  },
  "devDependencies": {
    "babel-jest": "19.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "19.0.2",
    "react-test-renderer": "15.4.2",
    "remote-redux-devtools": "^0.5.7",
    "chai": "*",
    "chai-as-promised": "*",
    "colors": "*",
    "mocha": "*",
    "q": "*",
    "underscore": "*",
    "wd": "*",
    "eslint": "^3.1.1",
    "eslint-plugin-react": "^5.2.2",
    "eslint-plugin-react-native": "^1.1.0",
    "babel-eslint": "^6.1.2"
  }
AsyncStorage Bug Help Wanted Locked

Most helpful comment

wow, there is still no response to this issue...

qq c7qbl o18a0u 3 m

All 92 comments

We're cutting down on the number of outstanding issues, in order to allow us to focus. I'm closing this issue because it has been open for over 60 days with no activity. If you think it should still be opened let us know why. PRs are always welcome.

any update? see the same problem

@YouHan26 This issue has stopped for me. Not sure what the reason is, but have you tried upgrading react native to the latest version?

@bartolkaruza I try to use real phone to test, It's ok. maybe just because of simulator

Still broken on react native 0.46.4 on a real device.

@hramos please reopen. AsyncStorage is a key component of react native and it's currently unusable when debugging.

I'm experiencing the same issue. RN 48, Genymotion running android 7

i am having the same issue. Anyone had any solution?
Edit: It worked on real device. So seems like problem is in genymotion

This is happening for me fairly consistently with RN 0.50.3. I can refresh my app a couple times with the multiGet promise completing, but after that the promise no longer completes. Issuing a react-native run-android will allow the multiget to return. This is happening with an Android Emulator API version 26.

Same issue.

I think this problem should be payed attention.

I have the same problem
Tested:
Android virtual machine (genymotion)
Android real machine

`console.log('beforereadtoken')
try {
let token = await AsyncStorage.getItem('fb_token');
} catch(e) {
console.log('there was an error');
console.log(e);
}

console.log('afterreadtoken')`

The second console.log does not get printed, also no errors are printed

I have same problem on Android. Statements after 'await' are never executed. My 'workaround' for now is to kill and relaunch the app, then it starts working for some time. (react-native 0.51.0)

Same problem here using node v8.8.1, npm v5.6, RN v0.50.4 and debugging using chrome 62.

I'm using a real device by the way

Hi this was happening to me until I ran "react-native run-android" again. I seem to need to do this everytime I import AsyncStorage to a new file.

Same issue on Android with real device, after reload the device. When it happened, I must kill the app and relaunch.

Can we re-open this issue? @bartolkaruza

RN v0.51.0

@hramos There seems to be regular activity on this issue on very recent versions, even though I have not experienced it myself recently. Could you re-open it?

+1 Same issue on Android, have to restarting app

This issue is also a regular problem that occurs on redux-persist project. (https://github.com/rt2zz/redux-persist/issues/603#issuecomment-360215088)

Having the same issue out of the blue from one day to another without changing anything on my react-native project!

+1 Same issue on Android 6, API Level 23. I resolve this issue by rerun 'react-native run-android'.

+1

+1. Any update on this ? This is a issue worth looking into. cannot go ahead with this for production apps.

I've been able to confirm that this is as a result of some kind of blocking in Android when debugging with an emulator.

A fix would definitely be nice.

It's still happening, even in recent react native version. It's very annoying, why this issue not prioritize to solve?

Btw it's happening even the debugging is not active. And it's happen in emulator and real devices. 馃憥

If it would help you:

I discovered this issue only now after starting to use VSC debugger or RNDebugger. I've always debugged in Chrome before and never ever experienced any AsyncStorage failures. So I tried now a few times in Chrome (opening&closing remote debugging session from app) and in Chrome it's fine.

What else have I observed:

  1. When you start debugging session in VSC/RND and never exit dbg mode, it's fine (though slow of course)
  2. When you exit remote dbg and AsyncStorage gets screwed up, when you do 'react'native run-android' again the issue is gone

+1

even callback not work, there is no solution, for me its a very critical bug

+1

+1 this happens to me but with setItem

This is indeed a very critical one,
One workaround for debugging is - stop debugging, rebuild the app again

and check logs via react-native log-android
Also, the same logs can be checked at logcat in android studio

P.S: Using RN 0.54

This seems to have gotten worse now. Normally I could refresh a few times, but now it isn't working at all.

Solution I currently have: 1. Launch app using android studio. 2. Quit android studio. 3. Restart app.

Even this doesn't always work.

@Jono20201 try uninstalling and installing the app again?

@Bryze Tired that. Even if that did work this needs to be addressed properly.

RN: 0.54.2
@all what's wrong with AsyncStorage? it's not working, even I've closed the remote debugger and none errors showing here.

Same issue here with RN 0.53.3, this is a very critical bug even in non debug mode.

Same issue here with RN 0.54.0, any updates?

in case it helps anyone:

on ios simulator and iphone 6+, it works for me with:
React Native Debugger (0.7.17)
react-native 0.53.3

but not with dev tools

the same problem
react-native 0.54.0-rc.3
debugging with true device

Happens every time for me, very painful because my app is working with AsyncStorage and restarting app every time I need to test my code hurts me at bottom. react-native run-android helps but only for 1-2 calls of await AsyncStorage.getItem() and then again its stuck.
RN 0.53.3;

Initially, asyncStorage showed up in Reactotron's timeline, but now, even that has stopped happening. There is no action whatsoever when I try to save or get any data from asyncStorage.

wow, there is still no response to this issue...

qq c7qbl o18a0u 3 m

Yep, pretty annoying. Any alternatives to async storage? Realm?

@reetou @KartikShankhavaram @lanlin @uruir does it work for you guys with the React Native Debugger app? It does for me!

+1

use react-native-async-storage-dev-menu-item if you wish to see your asyncStorage data in the console

@mvayngrib Worked for some time, now it doesnt.

have same problem, android emulator, "react-native": "^0.50.0",

:( Its look like Facebook team don't care about it, many and many days ago, and nothing

i don't have time to try it myself, but maybe someone try something like git bisect on the react-native release history (or just commit history) to see which commit introduced this bug.

I've met the same problem using emulator, But I found kill the debugging application, and reopen it, getItem won't block anymore

same here

same here

For me the only solution to debug AsyncStorage was react-native log-android

This is pretty consistent for me. First time I run the app on the Android emulator, await AsyncStorage.getItem returns a value. The moment I hit RR to reload, execution stops at this line and any further calls to AsyncStorage.getItem also fail to fulfill the promise. The only way out is to run the app again using react-native run-android. Using version 0.54.2.

Its frustrating, I hope we get a fix for this soon.

Same problem here on a real Android device. Moving to Realm as I need a fix right...

I got the same problem on when running on android device.

    try {
        userToken = await AsyncStorage.getItem(USER_TOKEN)
    } catch (error) {
        console.log('error is ', error);
    }
    console.log('userToken', userToken)

No error displayed. The console after this is not shown. Somehow AsyncStorage.getItem did not resolve or reject. Even when the remote debugging and it still does not work. This sounds like a core feature.

+1

Is there any alternative approach/module/library/workaround to this? Some simple key-value storage?

+1

+1

+1

At least on Android, on at least an emulator, and on at least a debug build, after reloading the app by pressing 'r' twice or through the developer menu by clicking "Reload", I often run into this issue where the first AsyncStorage.getItem call never hits a .then or .catch chained off of it.

It does not matter for me whether a debugger is attached or not.

Closing the app and then starting it resolves the issue. It is just very tedious and time consuming to do that often.

Does anyone knows whether this affect build (production) release?

Same here.

@sydneywu absolutely not

can confirm that after killing the app and then starting it again asyncstorage works fine

When can we expect an update for this issue?

+1

+1

+1bitmoji

+1

+1

as far as i know we cant use local storage in RN, so if we can't debug our apps when using Asyncstorage, what on earth we can do to store some data locally on the device?

+1

+1

+1

+1

+1 :(

+1

+1

+1

+1

+1

+1

This issue is opened for more than year but still nothing. That's really sad. Someone really need to look at it.

+1

+1

+1

+1

Locking due to +1 spam. Issue's still open in case any one wants to volunteer a fix.

This issue has been moved to react-native-community/react-native-async-storage#11.

Was this page helpful?
0 / 5 - 0 ratings