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

AsyncStorage conflict between core and communit #3422

Closed
rogueturnip opened this issue Jun 8, 2019 · 41 comments
Closed

AsyncStorage conflict between core and communit #3422

rogueturnip opened this issue Jun 8, 2019 · 41 comments
Assignees
Labels
question General question React Native React Native related issue

Comments

@rogueturnip
Copy link

I wanted to put this out to help accelerate the conversion to the community version of asyncstorage.

It appears there is a race condition if both community version and core version are being used on iOS. It causes both to try to write to the same file and thus overwrite each other. See this github issue here:
react-native-async-storage/async-storage#118 (comment)

@paul-doherty
Copy link

I second this. Recently found this as well. For me it manifested in logins being persisted to Async storage but closing the app and restarting it I am forced to login again. I eventually tracked it down and AsyncStorage.getItem was returning undefined for values that were present in the storage.

This is pretty serious if we cannot rely on Async storage

@haverchuck haverchuck added React Native React Native related issue needs-discussion Used for internal discussions labels Jun 10, 2019
@rogueturnip
Copy link
Author

I suspect moving to the community asyncstorage would be need to be a major release because switching this out in a minor release will break people that are still using the core asyncstorage in their app.

@jessedoyle
Copy link
Contributor

jessedoyle commented Jun 10, 2019

@rogueturnip

I suspect moving to the community asyncstorage would be need to be a major release

I made a comment on another issue here with a proposal for backwards-compatible dependency injection.

For ease of reference, I propose something along the lines of:

import MyAsyncStorage from '@react-native-community/async-storage';

Amplify.configure({
  ...
  Dependencies: {
    AsyncStorage: MyAsyncStorage, // would default to react-native provided AsyncStorage
  },
  ...
});

@haverchuck
Copy link
Contributor

@rogueturnip Disclaimer: I am not super familiar with this ongoing issue with RN AsyncStorage. If this issue you are having is specific to the Auth module with Amplify, could you try writing your own storage wrapper for Auth (which Amplify supports as outlined here) to use whichever specific version of AsyncStorage you want?

@rogueturnip
Copy link
Author

Thanks! I will do that when I get back to upgrading the AsyncStorage. I looked at the custom storage wrapper example that used AsyncStorage. I couldn't get it to work. I wasn't sure where MemoryStorage came from to import it.

@tallpants
Copy link
Contributor

tallpants commented Jun 21, 2019

We should move Amplify over to using @react-native-community/async-storage because AsyncStorage is being removed from React Native core in the next release (0.60) which should be out in a few weeks -- which means someone who react-native inits a new application and follows the instructions on Amplify's docs exactly will end up with a broken app.

Using your own storage wrapper should work, but it's not a good experience to have a broken app by default.

This would probably necessitate a major release since we'd need people to install and link @react-native-community/async-storage first to use Amplify (unless they're on Expo).

In the meantime I'd at least suggest adding this issue and the workaround to the docs because it's pretty serious to not be able to rely on async storage @haverchuck. I'd be happy to open a PR for it if you can tell me where in the docs it'd be most appropriate to put this!

@tallpants
Copy link
Contributor

Also cc @powerful23 just so you're aware of this

@willdady
Copy link

Moving to @react-native-community/async-storage needs to be done however I think it would be good to be able to override the default with your own storage engine similar to what @jessedoyle is saying above. The problem is you can't use AsyncStorage from core and the community one in the same app. It's one or the other. Being able to choose which storage engine could make the transition to using the community one easier, especially if you still have other dependencies in your app using AsyncStorage from core.

@mllrmat
Copy link

mllrmat commented Jul 29, 2019

Is there any progress on this issue? This is a pressing issue for me as it breaks functionality and can lead to some very strange side effects.
E.g. If I use amplify which uses the core async storage and another dependency which uses the new one, those dependencies will overwrite each others changes.

@joelfsreis
Copy link

I would like to know as well if progress are being made. We upgraded RN to latest version and we use amplify-js, so any input on the issue update would be much appreciated

@taschik
Copy link

taschik commented Aug 1, 2019

Is there any update from @rogueturnip ? Right now, aws-amplify is not usable with current RN 0.60.X as it can't persist the authentication. So either having a hotfix for the community version or the specification of a custom storage via configuration would be desirable.

@anthonyjoeseph
Copy link

Thanks! I will do that when I get back to upgrading the AsyncStorage. I looked at the custom storage wrapper example that used AsyncStorage. I couldn't get it to work. I wasn't sure where MemoryStorage came from to import it.

@rogueturnip using MyStorage instead of MemoryStorage works

@rogueturnip
Copy link
Author

I switched back to the old asyncstorage for the time being because of time. @anthonyjoeseph would you be willing to post your solution for everyone?

@anthonyjoeseph
Copy link

https://gist.github.com/anthonyjoeseph/16ab868408bb874a742fdf77d0be3fd1

@anthonyjoeseph
Copy link

anthonyjoeseph commented Aug 3, 2019

My guess is that the MyStorage implementation referenced in the amplify docs is an imperfectly modified version of the actual MemoryStorage implementation used in amplify, which is why there's that confusing static reference to MemoryStorage.syncPromise, and the unused static variable MyStorage.syncPromise.

@rogueturnip
Copy link
Author

Thanks so much! if anyone from AWS is reading this it would make alot of sense to use @anthonyjoeseph example in your documentation and comment on the conflict with RN 0.60.

@taschik
Copy link

taschik commented Aug 22, 2019

@rogueturnip I saw your post here: react-native-async-storage/async-storage#118 and was wondering what your final solution for the problem here is.

Are you using the custom storage workaround or did you downgrade to an older version of async-storage? and if so which version? Thanks so much for the support!

@rogueturnip
Copy link
Author

rogueturnip commented Aug 22, 2019 via email

@kirkryan
Copy link

This caused a bug that took days to track down - Please ensure that Amplify is updated to use the react-native-community async-storage, please!

@lenarmazitov
Copy link

I have same bug, and as a result I have troubles with my own redux-persist store. I can not clean it.

@TomJKlug
Copy link

This also caused a huge headache. Would greatly appreciate a switch the the react-native-community/async-storage

@mllrmat
Copy link

mllrmat commented Oct 30, 2019

Is there any progress on this issue?

@lvlrSajjad
Copy link

@mllrmat just replace

  private static syncPromise = null;

with

  static syncPromise = null;

@Ashish-Nanda Ashish-Nanda self-assigned this Nov 1, 2019
@lafiosca
Copy link
Contributor

lafiosca commented Nov 5, 2019

One thing I don't understand just looking at this file: is there some logic elsewhere that clears syncPromise, or can the sync method effectively only ever be used once? (And if the latter, is that intentional? Just meant as an initialization method?)

Edited to answer my own question: it appears the sync method is called during the configure method: https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/Auth.ts#L172-L175

@lafiosca
Copy link
Contributor

lafiosca commented Nov 6, 2019

Based on @mllrmat 's code above, I made a more TypeScript-y version: https://gist.github.com/lafiosca/774fa014d3326fcc992b55198ac5ea1d

While working on this, I found several things about the storage module interface odd; for example, setItem returns the value being set, but it doesn't appear that the current lib code uses the return value. Seems to me it would be nicer if these methods could return Promises, but that would obviously require more invasive changes to the packages.

@stale
Copy link

stale bot commented Dec 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@joebernard
Copy link

Bad bot, not stale.

@camin-mccluskey
Copy link

camin-mccluskey commented Dec 31, 2019

Any update on this? This is causing a major bug (logged out users on each app start) on a production application

@stale
Copy link

stale bot commented Jan 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@jessedoyle
Copy link
Contributor

This is still very much a significant issue. Please don't mark the issue as stale.

@stale
Copy link

stale bot commented Feb 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Off2Race
Copy link

This is still an issue. Many of us have worked around the problem but it should be fixed. Please don't mark the issue as stale.

@alexpanov
Copy link

This makes me want to migrate away from amplify. What a damn shame.

@sammartinez sammartinez added the question General question label Mar 5, 2020
@Ashish-Nanda
Copy link
Contributor

@alexpanov @Off2Race @jessedoyle

What exactly are the major issues you are facing? Is it the one mentioned in the original issue description: react-native-async-storage/async-storage#118

Can you explain how the issue manifests in your app?

Currently AsycnStorage is still a part of ReactNative, although there is a deprecation warning it still works fine.

I had previously created a PR to migrate to the community edition of AsyncStorage #4402

However we didnt end up releasing that as expo users would need to eject their app, since the community edition of AsyncStorage was not available for expo managed apps at the time. This would be a major issue if all our expo users now had to eject their apps.

So we are currently waiting for expo to add this dependency so that we can migrate Amplify JS to use react-native-community/async-storage. However let us know your issues and maybe we can come up with a workaround.

@mauerbac
Copy link
Member

hi @alexpanov - sorry to hear that. Following up on this -- are you still facing this issue?

@stale
Copy link

stale bot commented Apr 23, 2020

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@iamstiil
Copy link

FYI: Expo moved to the comminity package :)
Reference

@sotomaque
Copy link

updates on this?

@Ashish-Nanda
Copy link
Contributor

Hi All,
The PR #8250 to migrate to the community version of AsyncStorage has just been merged to main.
Please refer #6031 (comment) for latest updates on the release.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server amplify-help forum.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question General question React Native React Native related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.