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

Auth.signIn() promise takes more than 30 seconds to resolve on Android #5539

Closed
jfaq89 opened this issue Apr 24, 2020 · 58 comments
Closed

Auth.signIn() promise takes more than 30 seconds to resolve on Android #5539

jfaq89 opened this issue Apr 24, 2020 · 58 comments
Assignees
Labels
Auth Related to Auth components/category not-reproducible Not able to reproduce the issue React Native React Native related issue

Comments

@jfaq89
Copy link

jfaq89 commented Apr 24, 2020

Describe the bug
Auth.signIn() promise can take more than 30 seconds to resolve on Android. On iOS and Web we could not reproduce the bug.
It happens when we start the app and we click "Login" for the first time. It doesn't always happen, we have to try a few times to reproduce it.

To Reproduce
Steps to reproduce the behavior:

  1. Close all apps on device.
  2. Start React Native app using npx react-native run-android
  3. Click on "Login"
  4. See console to see how many miliseconds it took to complete the authentication.

Expected behavior
It should always be complete under 3 seconds as it happens on the other platforms.

Code Snippet

App.tsx :

import React from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import Amplify, { Auth } from "aws-amplify";
import {awsmobileDev} from './aws-exports'
Amplify.configure(awsmobileDev);

export default class App extends React.Component<{}, {}> {
  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity
          style={{ height: 50, width: 200 }}
          onPress={async () => {
            console.log("Signing in...");
            const timeStart = new Date().getTime();
            await Auth.signIn("username", "password");
            const timeEnd = new Date().getTime();
            console.log("Sign in successfull. ", timeEnd - timeStart);
          }}
        >
          <Text>Login</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

Screenshots
Bildschirmfoto 2020-04-24 um 15 23 45
Here for example, it lasted 128 seconds to login!

What is Configured?
If applicable, please provide what is configured for Amplify CLI:

  • Which steps did you follow via Amplify CLI when configuring your resources.
  • Which resources do you have configured?
    • If applicable, please provide your aws-exports file:
    const awsmobile = {
    aws_project_region: "eu-central-1",
    aws_cognito_identity_pool_id:
     "eu-central-1:xxx",
    aws_cognito_region: "eu-central-1",
    aws_user_pools_id: "eu-central-1_xxx",
    aws_user_pools_web_client_id: "xxx",
    oauth: {},
    aws_appsync_graphqlEndpoint:
     "https://xxx.appsync-api.eu-central-1.amazonaws.com/graphql",
    aws_appsync_region: "eu-central-1",
    aws_appsync_authenticationType: "AMAZON_COGNITO_USER_POOLS",
    aws_cloud_logic_custom: [
     {
       name: "xxx",
       endpoint: "https://xxx.execute-api.eu-central-1.amazonaws.com/dev",
       region: "eu-central-1",
     },
    ],
    aws_mobile_analytics_app_id: "xxx",
    aws_mobile_analytics_app_region: "eu-central-1",
    aws_user_files_s3_bucket: "xxx-dev",
    aws_user_files_s3_bucket_region: "eu-central-1",

};
};

**Smartphone (please complete the following information):**

- Device: We can see it in all kinds of Android Devices


@jfaq89 jfaq89 added the to-be-reproduced Used in order for Amplify to reproduce said issue label Apr 24, 2020
@amhinson
Copy link
Contributor

amhinson commented Apr 24, 2020

@jfaq89 I see that you're testing with a development React Native build. Could you also test with a production build on a physical device and verify that you're seeing the same behavior?

Also, what version of aws-amplify are you using?

@amhinson amhinson added Auth Related to Auth components/category React Native React Native related issue labels Apr 24, 2020
@jfaq89
Copy link
Author

jfaq89 commented Apr 25, 2020

@jfaq89 I see that you're testing with a development React Native build. Could you also test with a production build on a physical device and verify that you're seeing the same behavior?

Also, what version of aws-amplify are you using?

Hi. We already saw the error in production. Many people from my team have tested using different physical devices and everyone managed to reproduce the error.

We tested using the latest version of AWS-amplify.

@jfaq89
Copy link
Author

jfaq89 commented Apr 27, 2020

We're still blocked. The error was seen using version 3.0.9

Any idea how we can fix this?

@amhinson
Copy link
Contributor

@jfaq89 A couple of questions/comments:

  • What version of React Native are you using?
  • What other Amplify categories are you using in your app?
  • Could you try reproducing this behavior with a brand new basic app and share it here?

I've got a simple auth app for testing, but I haven't been able to duplicate the issue you're seeing after trying numerous times on an Android device.

@jfaq89
Copy link
Author

jfaq89 commented Apr 28, 2020

@jfaq89 A couple of questions/comments:

  • What version of React Native are you using?
  • What other Amplify categories are you using in your app?
  • Could you try reproducing this behavior with a brand new basic app and share it here?

I've got a simple auth app for testing, but I haven't been able to duplicate the issue you're seeing after trying numerous times on an Android device.

  1. React Native version : 0.61.5
  2. On this brand new basic app that I made to debug this problem, I only use "Auth".
  3. Here is the code: (the awsmobileDev config is the one I posted above)
import React from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import { Auth } from "aws-amplify";
import {awsmobileDev} from './aws-exports'

Auth.configure(awsmobileDev);

// Amplify.Logger.LOG_LEVEL = "DEBUG";
export default class App extends React.Component<{}, {}> {
  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity
          style={{ height: 50, width: 200 }}
          onPress={async () => {
            console.log("Signing in...");
            const timeStart = new Date().getTime();
            await Auth.signIn("[email protected]", "password");
            const timeEnd = new Date().getTime();
            console.log("Sign in successfull. ", timeEnd - timeStart);
          }}
        >
          <Text style={{ textAlign: "center" }}>Login</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});


It is not very easy to reproduce the error. You have to try a few times. It is easier to reproduce on a physical device than on a simulator.

Thanks in advance. Looking forward to hear from you!

@jfaq89
Copy link
Author

jfaq89 commented Apr 28, 2020

New information : we managed to reproduce it on an iPhone device. The Auth.signIn promise lasted 31 seconds. So it is also possible to see in an iPhone, but much harder to reproduce the error.

@amhinson amhinson added not-reproducible Not able to reproduce the issue and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Apr 28, 2020
@jfaq89
Copy link
Author

jfaq89 commented May 6, 2020

Anyone has any ideas? If we cannot solve it, then is there maybe a possible workaround?

@amhinson
Copy link
Contributor

amhinson commented May 6, 2020

Unfortunately we have had no luck trying to reproduce this issue on our end using multiple devices/simulators/emulators. However, we can still leave this issue open in case others might be experiencing it as well in the future.

@batical
Copy link

batical commented Jun 2, 2020

one of my beta tester is facing this issue but worse.
I took more than 10 minutes on her android. She tried with 3 different android in the same network wifi, same version of app and 4 iOS device with no issue.

I will be able to to more test in debug mode with this phone Friday. Don't know exactly what to look

Edit : I test to call the login in a thunk redux, in saga, or alone. Using promise or async. The result is the same. It is taking more than 10 minutes; Reactotron does not see any outgoing network request and I got no error in android studio log

@Andyluchina
Copy link

I am experiencing the same issue, but with ionic+angular on android devices.
"@ionic/angular": "^4.11.10",
"aws-amplify": "^3.0.10",
"aws-amplify-angular": "^5.0.10"

The tester is reporting a long wait time for sign in, and it seems to me that amplify is calling the cognito server about 12 times for a single Auth.signin, and the accumulated time of all these requests took this long. I am suspecting this is both related to network and the implementation of the frontend code.

@batical
Copy link

batical commented Jun 30, 2020

one of my beta tester is facing this issue but worse.
I took more than 10 minutes on her android. She tried with 3 different android in the same network wifi, same version of app and 4 iOS device with no issue.

I will be able to to more test in debug mode with this phone Friday. Don't know exactly what to look

Edit : I test to call the login in a thunk redux, in saga, or alone. Using promise or async. The result is the same. It is taking more than 10 minutes; Reactotron does not see any outgoing network request and I got no error in android studio log

When I wrote my previous message, I was getting amplify by package in react native
@aws-amplify/auth api and storage.

I switch to using aws-amplify full package (with latest version) and the issue seems to have disappear. (in release mode)

@standemchuk
Copy link

Experiencing the same issue with latest expo and even clean RN. The call to SignIn can is steady at 40-60s on a clean app that just does SignIn, no other logic. Sometimes it can take up to 3 min 😮
Anyone close to a solution or a workaround?

@amhinson
Copy link
Contributor

@standemchuk If you could provide a sample repo that consistently shows this behavior, that would be wonderful! So far, I've been unable to reproduce the issue described.

@standemchuk
Copy link

@amhinson Hi and thanks for a quick reaction!
Here's a repo on which we're trying to find a fix for an issue: https://github.com/standemchuk/amplify-rn-long-response-repro
Please make sure you update the values for userPoolId and userPoolWebClientId, they're currently marked as SUBSTITUTE_ME.

@standemchuk
Copy link

@amhinson sorry, just pushed a small updated to make sure the app launches, please pull the latest changes

@standemchuk
Copy link

@amhinson were you able to reproduce the issue?

@rbrazhnyk
Copy link

@amhinson the issue can be reproduced on android emulator and android phone only. No issues if testing in the browser (had rare issues in iOS though).

@amhinson
Copy link
Contributor

@standemchuk So far I have not been able to replicate it. Would you be able to share the steps you took after running amplify add auth? There could be a certain configuration that might be causing issues.

@rbrazhnyk
Copy link

@amhinson, according to the docs we don't have to create authentication service from scratch by running amplify add auth, but rather we can re-use existing authentication resources.
We added amplify configuration and make a single call Auth.SignIn.

I am able to reproduce the issue now with the codebase we provide (please also see screenshots below). Sometimes we got the response within 0.5s (which is okay), but usually, it is 10 seconds or worse (81s in the second example).

0 5s

81s

@amhinson
Copy link
Contributor

Are you using any custom Lambda triggers, by chance?

@rbrazhnyk
Copy link

@amhinson, yes we have custom triggers.

So for the sake of experiment, I've just created a new Cognito UserPool with no custom triggers.

Screen Shot 2020-07-28 at 9 05 56 AM

Here are the settings of the new pool:
Screen Shot 2020-07-28 at 9 10 00 AM
Screen Shot 2020-07-28 at 9 10 30 AM
Screen Shot 2020-07-28 at 9 10 55 AM
Screen Shot 2020-07-28 at 9 11 29 AM
Screen Shot 2020-07-28 at 9 11 41 AM

@amhinson
Copy link
Contributor

@rbrazhnyk Would you be able to reach out to me on our Discord? I'm still not able to reproduce the issue, but it could be helpful for me to test directly against your new User Pool.

@rbrazhnyk
Copy link

rbrazhnyk commented Jul 29, 2020

@amhinson what is your username in Discord? amhinson does not return anything in seach results.
My username is rbrazhnyk (rbrazhnyk#7957) there. Perhaps you can ping me.

P.S. I find out how that works. I've sent you a friend request.

@stale
Copy link

stale bot commented Aug 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.

@IanPhilips
Copy link

I was having this issue after developing out my web version for a while and started testing on my mobile builds. I found my android build was working and navigating fine but amplify's signIn() method was taking forever. I went to check and see what was going on with my iOS build and it wouldn't navigate from my root view. It was throwing this error. Upon resetting my babel.config.js to the basic module.exports = { presets: ['@expo/next-adapter/babel']}; and then starting expo cleanly via expo start -c the amplify sign in method now works like a charm on both OS's!

@stale
Copy link

stale bot commented Jun 9, 2021

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.

@tars0x9752
Copy link

tars0x9752 commented Jul 7, 2021

I'm not sure if it's exactly the same as this issue, but I experienced extremely slow Auth.signIn on both iOS and Android. Only on the actual device, the problem does not occur on the emulator. It takes at least 8~10 seconds to resolve Auth.signIn each time on iOS. On android it takes even more seconds.

And somehow I fixed it, so I'll leave some workaround that might be worth trying.

  • Remove resolverMainFields in metro.config.js if possible. If you can't remove resolverMainFields completely, at least get rid of module from resolverMainFields.
  • If you have Hermes enabled, try disabling it.

In my case, got rid of 'module' from resolverMainFields fixed the problem. Hope this helps someone.

@mudrila
Copy link

mudrila commented Jul 14, 2021

I was having this issue after developing out my web version for a while and started testing on my mobile builds. I found my android build was working and navigating fine but amplify's signIn() method was taking forever. I went to check and see what was going on with my iOS build and it wouldn't navigate from my root view. It was throwing this error. Upon resetting my babel.config.js to the basic module.exports = { presets: ['@expo/next-adapter/babel']}; and then starting expo cleanly via expo start -c the amplify sign in method now works like a charm on both OS's!

Was causing issues for me as well - I added react-native-paper/babel to my babel.config.js and after removing that - everything works like a charm!

@dloaizarico
Copy link

Hi Everyone, I am having the same issue with an app created as follows:

> What version of React and Amplify are you using?
Amplify "^3.3.20", "@aws-amplify/auth": "^3.4.23" and React "^16.13.1"
> Is there a custom Lambda trigger involved in your setup:
There were custom triggers but even after removing them, the delay is still happening.
> Network request data: from a tool such as Flipper or Reactotron, please find attached a file with the logs I could get and also some images of my console.
test
test2
localhost-1633932330391.log

@andreialecu
Copy link
Contributor

andreialecu commented Dec 9, 2021

Suddenly started running into this issue as well on a physical Android device with React Native. On iOS everything is fine.

It appears that any Auth network calls are not even issued. I can't see anything in Flipper.

Notice how this fetch doesn't seem to get to its then below based on my logging (This is in amazon-cognito-identity-js):
Screenshot 2021-12-09 at 18 21 24

Then after several minutes there's a burst of network calls and the issue seems to clear up for a bit:

Screenshot 2021-12-09 at 18 15 53

❗ It appears that saving any file so that RN does a hot-reload will unblock the promise and issue the network request.

Other network calls the app makes seem to be fine, it's only Cognito that seems to have this problem. Very strange.

@andreialecu
Copy link
Contributor

It appears that this may be some sort of React Native issue with IPv6 on Android.

I've applied the workaround in: facebook/react-native#29608 (comment) and now requests seem to go through. That entire thread is about requests getting stuck on Android.

Here's the second log line being logged correctly with the IPv4 DNS resolver from the link:

Screenshot 2021-12-09 at 19 03 36

@andreialecu
Copy link
Contributor

andreialecu commented Dec 9, 2021

Opened facebook/react-native#32730 for react-native.

I left a more detailed write-up here: facebook/react-native#32730 (comment)

@vankhoa01
Copy link

Hi my friends,

I got same issue.
Is there anyone else have resolved this problem ?

This is aws version which I'm using in my application
Screen Shot 2022-05-17 at 11 00 48

@msaraac
Copy link

msaraac commented Sep 16, 2022

any suggestions here. I'm getting same problem. There is no issue with ios device but in android when I call the auth.signIn application got stuck and fps drops to -2

@dzpincus
Copy link

dzpincus commented Nov 2, 2022

I'm facing the same issue. The sign in call was working perfectly fine until recently, now takes up to a minute or two.
Has anyone figured out the issue yet?

@HodayaGruz
Copy link

is there solution for this? i have 2 application with one aws source code, on one works prefect and on the other the app stuck for 10 sec

@Sean-Kurian
Copy link

I am also running into this issue on a new app, it worked instantaneously for a bit and now hangs as described above.

@JKKholmatov
Copy link

@HodayaGruz @Sean-Kurian Did you find any solution?

@HodayaGruz
Copy link

@JKKholmatov In my case, I was need to create new app and copy all the code (I guess the problem was relevant to react native version)

@cwomack
Copy link
Member

cwomack commented Dec 5, 2023

With the release of the latest major version of Amplify (aws-amplify@>6), we believe this issue should now be resolved. Since we could not reproduce this issue on our side, would anyone be able to confirm after migrating to v6 if this is still an issue?

Please refer to our release announcement, migration guide, and documentation for more information.

@cwomack
Copy link
Member

cwomack commented Dec 21, 2023

We'll close this issue on our side as it seems to be awaiting fixes on Facebook's React Native repo as detailed in #32730 on their repo. If someone has an easy way to reproduce this on the Amplify JS library side, please feel free to respond with those details and we can reopen this issue.

@cwomack cwomack closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category not-reproducible Not able to reproduce the issue React Native React Native related issue
Projects
None yet
Development

No branches or pull requests