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] faulty fetchAuthSession #3583

Closed
1 of 14 tasks
charlieforward9 opened this issue Aug 19, 2023 · 31 comments
Closed
1 of 14 tasks

[Auth] faulty fetchAuthSession #3583

charlieforward9 opened this issue Aug 19, 2023 · 31 comments
Assignees
Labels
auth Issues related to the Auth Category not-reproducible Issues that cannot be reproduced using the steps provided pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.

Comments

@charlieforward9
Copy link

Description

This is my Amplify function:

  Future<AuthSession?> fetch() async {
    AuthSession? session;
    try {
      session = await Amplify.Auth.fetchAuthSession();
    } catch (e) {
      log("fetch function failed to return a AuthSession with error $e");
    }
    return session;
  }

and here is where I call it:

FutureOr<void> _onAuto(AuthAuto event, Emitter<AuthState> emit) async {
    if (isClosed) {
      emit(AuthError(error: Exception("AuthBloc is closed")));
    }
    try {
      final session = await auth.fetch();
      log(session.toString(), name: "Session");
      if (session != null && session.isSignedIn) {
        ...
      }
    } catch (e) {
      emit(AuthError(error: Exception("Failed to auto auth")));
    }
  }

when I run my application, it crashes, pausing the main isolate, and showing this call stack in the 'Run & Debug' tab.

AWSRetryer.retry. (/Users/crich/.pub-cache/hosted/pub.dev/smithy_aws-0.5.1/lib/src/http/retry/aws_retryer.dart:196)
(Unknown Source:0)

Additionally, I get this log in my debug console when restarting the app: fetch function failed to return a AuthSession with error Bad state: Cannot add event after closing

If I click the 'continue' button instead of the restart button, the _onAuth function logs this session object

{
            "isSignedIn": false,
            "userSub": "AWSErrorResult<String, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
            "userPoolTokens": "AWSErrorResult<CognitoUserPoolTokens, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
            "credentials": "AWSErrorResult<AWSCredentials, SessionExpiredException> {\n  \"exception\": {\n    \"message\": \"The AWS credentials could not be retrieved\",\n    \"recoverySuggestion\": \"Invoke Amplify.Auth.signIn to re-authenticate the user\",\n    \"underlyingException\": \"NotAuthorizedException {\\n  message=Unauthenticated access is not supported for this identity pool.,\\n}\"\n  },\n  \"stackTrace\": \"#0      HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\\n<asynchronous suspension>\\n#1      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)\\n<asynchronous suspension>\\n\"\n}",
            "identityId": "AWSErrorResult<String, SessionExpiredException> {\n  \"exception\": {\n    \"message\": \"The AWS credentials could not be retrieved\",\n    \"recoverySuggestion\": \"Invoke Amplify.Auth.signIn to re-authenticate the user\",\n    \"underlyingException\": \"NotAuthorizedException {\\n  message=Unauthenticated access is not supported for this identity pool.,\\n}\"\n  },\n  \"stackTrace\": \"#0      HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\\n<asynchronous suspension>\\n#1      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)\\n<asynchronous suspension>\\n\"\n}"
          }

the error is strange, as I have gotten the Bad state: Cannot add event after closing message before working with the bloc library. However, as it is catching the error within the try block, which is a single API call to the AWS ecosystem, I cant see how it could be my bloc library causing this issue.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.14.0-3.0.pre.38

Amplify Flutter Version

1.3.1 + 1.3.3

Deployment Method

Amplify CLI

Schema

No response

@charlieforward9 charlieforward9 changed the title fetchAuthSession not working as expected [Auth] faulty fetchAuthSession Aug 19, 2023
@dnys1
Copy link
Contributor

dnys1 commented Aug 20, 2023

Hi @charlieforward9, sorry you are facing this issue. Can you please try running your app without the debugger and provide a full stack trace for the error in question?

The Bad state: Cannot add event after closing error is likely coming from a StreamController, which could be one of those inside the bloc. Could the error be coming from this line? Emitting a state from a closed bloc may be trying to add that state to a closed stream controller.

    if (isClosed) {
      emit(AuthError(error: Exception("AuthBloc is closed")));
    }

@dnys1 dnys1 self-assigned this Aug 20, 2023
@dnys1 dnys1 added auth Issues related to the Auth Category pending-community-response Pending response from the issue opener or other community members pending-triage This issue is in the backlog of issues to triage labels Aug 20, 2023
@charlieforward9
Copy link
Author

charlieforward9 commented Aug 20, 2023

    if (isClosed) {
      emit(AuthError(error: Exception("AuthBloc is closed")));
    }

I realize this is error prone, however, I added this line after the fact while I was trying to debug the original error. Without it, the fault is still present.

I will try to get the log of the stack trace as well, but I am not running it from the debugger. I am running the app by going to my 'main.dart' and clicking the Run button that appears on the top right of the screen (using VSCode). Ill 'run without debugging' and see.

@charlieforward9
Copy link
Author

charlieforward9 commented Aug 20, 2023

@dnys1 The error does not throw when running without debugger. Howeer, when I reverted to using the debugger again, the problem persists

Full stacktrace [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Cannot add event after closing dart:async/stream_controller.dart 605:24 _StreamController.add package:async/src/stream_sink_completer.dart 118:27 _CompleterSink.add 2 package:async/src/stream_sink_transformer/handler_transformer.dart 59:14 _HandlerSink.add package:async/src/stream_sink_completer.dart 116:25 _CompleterSink.add package:worker_bee/src/common.dart 223:35 WorkerBeeCommon.add package:amplify_secure_storage_dart/src/amplify_secure_storage_dart.dart 137:13 AmplifySecureStorageWorker.delete ===== asynchronous gap =========================== dart:async/future.dart 523:21 Future.wait. ===== asynchronous gap =========================== package:amplify_auth_cognito_dart/src/state/machines/credential_store_state_machine.dart 410:5 CredentialStoreStateMachine.onClearCredentials ===== asynchronous gap =========================== package:amplify_auth_cognito_dart/src/state/machines/credential_store_state_machine.dart 63:9 CredentialStoreStateMachine.resolve ===== asynchronous gap =========================== package:amplify_core/src/state_machine/state_machine.dart 262:11 StateMachine._listenForEvents. ===== asynchronous gap =========================== package:amplify_core/src/state_machine/state_machine.dart 251:7 StateMachine._listenForEvents ===== asynchronous gap =========================== package:amplify_core/src/state_machine/event.dart 43:47 new EventCompleter package:amplify_core/src/state_machine/state_machine.dart 186:19 StateMachineManager.dispatch package:amplify_core/src/state_machine/state_machine.dart 32:23 Dispatcher.dispatchAndComplete package:amplify_core/src/state_machine/state_machine.dart 197:13 StateMachineManager.dispatchAndComplete package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart 90:11 CognitoAuthStateMachine.clearCredentials package:amplify_auth_cognito_dart/src/state/machines/fetch_auth_session_state_machine.dart 501:21 FetchAuthSessionStateMachine._retrieveAwsCredentials

@dnys1
Copy link
Contributor

dnys1 commented Aug 20, 2023

Thank you for sharing this, @charlieforward9. I will see if I can figure out how to reproduce it.

The error is coming from the Amplify Auth library, although I'm not sure how it could be happening. Would you be able to explain where in your startup process the fetchAuthSession model is called?

@dnys1
Copy link
Contributor

dnys1 commented Aug 20, 2023

Does this only happen when performing a hot restart?

@charlieforward9
Copy link
Author

charlieforward9 commented Aug 20, 2023

@dnys1 Thank you for your help.

Does this only happen when performing a hot restart?

No, when I do a fresh start with the debugger, it will pause...

Debug Console Log Launching lib/main.dart on Clearly Charlie in debug mode...

Automatically signing iOS for device deployment using specified development team in Xcode project: PHN85FQ74K

Xcode build done. 75.4s

(lldb) 2023-08-20 16:46:04.792579-0400 Runner[5228:477078] [VERBOSE-2:FlutterDarwinContextMetalImpeller.mm(37)] Using the Impeller rendering backend.
FFmpegKitFlutterPlugin 0x283a1c760 created.

Compiler failed to build request

[VERBOSE-2:validation.cc(49)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not create render pipeline: Fragment input(s) user(locn1) mismatching vertex shader output type(s) or not written by vertex shader

Connecting to VM Service at ws://127.0.0.1:60143/3F7XdUsnrFw=/ws

Initialized TensorFlow Lite runtime.

INFO: Initialized TensorFlow Lite runtime.

[Backend Bloc] Connecting to Backend

Amplify configured with DataStore plugin

[Connectivity] ConnectivityResult.wifi

[Amplify] Configuring

[awsAPIPlugin] Configure finished

[Amplify] No plugin found for configuration key awsS3StoragePlugin. Add a plugin for that key.

DataStorePlugin successfully initialized

[log] Ending timeout timer

[log] Attempting auto auth
<Isolate Pauses, when I resume it spits out...>
[Auto Auth] User is not signed in
[Session] {
"isSignedIn": false,
"userSub": "AWSErrorResult<String, SignedOutException> {\n "exception": {\n "message": "No user is currently signed in"\n },\n "stackTrace": null\n}",
"userPoolTokens": "AWSErrorResult<CognitoUserPoolTokens, SignedOutException> {\n "exception": {\n "message": "No user is currently signed in"\n },\n "stackTrace": null\n}",
"credentials": "AWSErrorResult<AWSCredentials, SessionExpiredException> {\n "exception": {\n "message": "The AWS credentials could not be retrieved",\n "recoverySuggestion": "Invoke Amplify.Auth.signIn to re-authenticate the user",\n "underlyingException": "NotAuthorizedException {\n message=Unauthenticated access is not supported for this identity pool.,\n}"\n },\n "stackTrace": "#0 HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\n\n#1 CancelableCompleter.complete. (package:async/src/cancelable_operation.dart:425:16)\n\n"\n}",
"identityId": "AWSErrorResult<String, SessionExpiredException> {\n "exception": {\n "message": "The AWS credentials could not be retrieved",\n "recoverySuggestion": "Invoke Amplify.Auth.signIn to re-authenticate the user",\n "underlyingException": "NotAuthorizedException {\n message=Unauthenticated access is not supported for this identity pool.,\n}"\n },\n "stackTrace": "#0 HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\n\n#1 CancelableCompleter.complete. (package:async/src/cancelable_operation.dart:425:16)\n\n"\n}"
}

I have my entire CupertinoApp inclosed in the AuthBloc provider, however, I do not do not add any events or make any Amplify.Auth calls until Amplify configuration is complete. After config, the user is automatically navigated to the Auth view, where I add 'AuthAuto' to the BLoC stream to attempt to sign in to the user with the existing local session. If the user has previously signed in, no error occurs. However, when there is no authenticated user, it throws. It is inside this 'AuthAuto' event that the problem occurs. The code for it is provided above.

@charlieforward9
Copy link
Author

charlieforward9 commented Aug 24, 2023

@dnys1 I decided to use Auth Hub Events to work around fetchAuthSession for AutoAuthenticating, but I am getting a similar error in the signUp API now. Like before, when I try to isolate the error, it looks like it is coming from inside Amplify.Auth.

Here is the snippet ...

emit(const AuthLoad(message: "Logging in..."));

try {
  final result = await auth.completeLogin();
  if (result == "done") {
    final user = await userService.setUser();
    if (!isClosed) emit(AuthSuccess(user: user));
  } else {
    if (!isClosed) emit(AuthCode(message: result));
  }
} catch (e) {
  if (!isClosed) emit(AuthSignUp(message: e.toString()));
}

with completeLogin() being:

  //Email and password passed in through class properties
  Future<String> completeLogin() async {
    try {
      final result =
          await Amplify.Auth.signIn(username: email, password: password);
      switch (result.nextStep.signInStep) {
        ...
        case AuthSignInStep.done:
          return "done";
      }
    } catch (e) {
      ... full coverage error handling
    }
  }

When I run this, my debugger will pause on Amplify.Auth.signIn. If I click continue 3 or 4 times, it will actually work, and log me in!

However, if I hot restart it, I get this:

Error Log package:amplify_auth_cognito_dart/src/state/machines/sign_in_state_machine.dart 855:9 SignInStateMachine.resolve package:amplify_core/src/state_machine/state_machine.dart 262:11 StateMachine._listenForEvents. package:amplify_core/src/state_machine/state_machine.dart 251:7 StateMachine._listenForEvents [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Cannot add event after closing dart:async/stream_controller.dart 605:24 _StreamController.add package:async/src/stream_sink_completer.dart 118:27 _CompleterSink.add 2 package:async/src/stream_sink_transformer/handler_transformer.dart 59:14 _HandlerSink.add package:async/src/stream_sink_completer.dart 116:25 _CompleterSink.add package:worker_bee/src/common.dart 223:35 WorkerBeeCommon.add package:amplify_secure_storage_dart/src/amplify_secure_storage_dart.dart 137:13 AmplifySecureStorageWorker.delete ===== asynchronous gap =========================== dart:async/future.dart 523:21 Future.wait. ===== asynchronous gap =========================== package:amplify_auth_cognito_dart/src/state/machines/credential_store_state_machine.dart 410:5 CredentialStoreStateMachine.onClearCredentials ===== asynchronous gap =========================== package:amplify_auth_cognito_dart/src/state/machines/credential_store_state_machine.dart 63:9 CredentialStoreStateMachine.resolve ===== asynchronous gap =========================== package:amplify_core/src/state_machine/state_machine.dart 262:11 StateMachine._listenForEvents. ===== asynchronous gap =========================== package:amplify_core/src/state_machine/state_machine.dart 251:7 StateMachine._listenForEvents ===== asynchronous gap =========================== package:amplify_core/src/state_machine/event.dart 43:47 new EventCompleter package:amplify_core/src/state_machine/state_machine.dart 186:19 StateMachineManager.dispatch package:amplify_core/src/state_machine/state_machine.dart 32:23 Dispatcher.dispatchAndComplete package:amplify_core/src/state_machine/state_machine.dart 197:13 StateMachineManager.dispatchAndComplete package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart 90:11 CognitoAuthStateMachine.clearCredentials package:amplify_auth_cognito_dart/src/state/machines/fetch_auth_session_state_machine.dart 501:21 FetchAuthSessionStateMachine._retrieveAwsCredentials package:amplify_auth_cognito_dart/src/state/machines/fetch_auth_session_state_machine.dart 429:38 FetchAuthSessionStateMachine.onRefresh package:amplify_auth_cognito_dart/src/state/machines/fetch_auth_session_state_machine.dart 81:11 FetchAuthSessionStateMachine.resolve package:amplify_auth_cognito_dart/src/state/machines/fetch_auth_session_state_machine.dart 75:11 FetchAuthSessionStateMachine.resolve package:amplify_core/src/state_machine/state_machine.dart 262:11 StateMachine._listenForEvents. package:amplify_core/src/state_machine/state_machine.dart 251:7 StateMachine._listenForEvents ===== asynchronous gap =========================== package:amplify_core/src/state_machine/event.dart 43:47 new EventCompleter package:amplify_core/src/state_machine/state_machine.dart 186:19 StateMachineManager.dispatch package:amplify_core/src/state_machine/state_machine.dart 32:23 Dispatcher.dispatchAndComplete package:amplify_core/src/state_machine/state_machine.dart 197:13 StateMachineManager.dispatchAndComplete package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart 95:32 CognitoAuthStateMachine.loadSession package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart 125:31 CognitoAuthStateMachine.getUserPoolTokens package:amplify_auth_cognito_dart/src/state/machines/sign_in_state_machine.dart 581:7 SignInStateMachine._assertSignedOut package:amplify_auth_cognito_dart/src/state/machines/sign_in_state_machine.dart 855:9 SignInStateMachine.resolve package:amplify_core/src/state_machine/state_machine.dart 262:11 StateMachine._listenForEvents. package:amplify_core/src/state_machine/state_machine.dart 251:7 StateMachine._listenForEvents ===== asynchronous gap =========================== package:amplify_core/src/state_machine/event.dart 43:47 new EventCompleter package:amplify_core/src/state_machine/state_machine.dart 157:23 StateMachineManager.accept package:amplify_core/src/state_machine/state_machine.dart 169:23 StateMachineManager.acceptAndComplete package:amplify_auth_cognito_dart/src/auth_plugin_impl.dart 555:42 AmplifyAuthCognitoDart.signIn package:amplify_core/src/category/amplify_auth_category.dart 469:29 AuthCategory.signIn. dart:async/zone.dart 1399:13 _rootRun dart:async/zone.dart 1301:19 _CustomZone.run dart:async/zone.dart 1804:10 _runZoned dart:async/zone.dart 1747:10 runZoned package:amplify_core/src/http/amplify_category_method.dart 147:10 identifyCall package:amplify_core/src/category/amplify_auth_category.dart 467:7 AuthCategory.signIn package:visualpt/service/auth_service.dart 64:30 AuthService.completeLogin

Furthermore, I re-designed the way that I configured Amplify before displaying the Auth UI. So I am 99.99% confident that it is not a config issue.

Some extra notes:

When I run without the debugger, it works without any issues.

I do get these log though:

  • The 'dev.flutter.pigeon.NativeAuthPlugin.fetchAuthSession' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

  • [Amplify] No plugin found for configuration key `awsS3StoragePlugin`. Add a plugin for that key.
    I cant imagine it is causing issues, as I use the storage calls later without any problems.

@dnys1
Copy link
Contributor

dnys1 commented Aug 24, 2023

Hi @charlieforward9, thank you for the continued investigation.

A few questions:

  • When you are debugging, do you have checked All Exceptions or Uncaught Exceptions or both in the breakpoints tab?
  • Does the error Bad state: Cannot add event after closing only happen when performing a hot restart? If so, it can be safely ignored. I am thinking of ways to improve it, but it will not affect your program in production.

Regarding the two suspicious log messages:

  • The 'dev.flutter.pigeon.NativeAuthPlugin.fetchAuthSession' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

This seems like a bug in our code which I will address.

  • [Amplify] No plugin found for configuration key awsS3StoragePlugin. Add a plugin for that key.

This one can be safely ignored. I will investigate the possibility of removing it, but it is not harmful.

@dnys1 dnys1 added Investigating and removed pending-triage This issue is in the backlog of issues to triage labels Aug 24, 2023
@charlieforward9
Copy link
Author

charlieforward9 commented Aug 24, 2023

@dnys1

When you are debugging, do you have checked All Exceptions or Uncaught Exceptions or both in the breakpoints tab?

Only Uncaught Exceptions

Does the error Bad state: Cannot add event after closing only happen when performing a hot restart? If so, it can be safely ignored. I am thinking of ways to improve it, but it will not affect your program in production.

This error occurs when it is launched for the first time, AND when it is hot restarted. It throws when I run fetchAuthSession and signUp, I have not attempted other APIs yet.

This seems like a bug in our code which I will address.

Thank you. Is this bug related to my issue?

@dnys1
Copy link
Contributor

dnys1 commented Aug 24, 2023

Is this bug related to my issue?

I'm not sure. I've opened this PR to fix it. Can you try adding a dependency override to test it?

dependency_overrides:
  amplify_datastore:
    git:
      url: https://github.com/aws-amplify/amplify-flutter/
      ref: fix/auth/platform-thread
      path: packages/amplify_datastore

@charlieforward9

This comment was marked as resolved.

@dnys1
Copy link
Contributor

dnys1 commented Aug 25, 2023

Sorry, here are the correct overrides:

dependency_overrides:
  amplify_datastore:
    git:
      url: https://github.com/aws-amplify/amplify-flutter/
      ref: fix/auth/platform-thread
      path: packages/amplify_datastore
  amplify_core:
    git:
      url: https://github.com/aws-amplify/amplify-flutter/
      ref: fix/auth/platform-thread
      path: packages/amplify_core
  aws_common:
    git:
      url: https://github.com/aws-amplify/amplify-flutter/
      ref: fix/auth/platform-thread
      path: packages/aws_common
  aws_signature_v4:
    git:
      url: https://github.com/aws-amplify/amplify-flutter/
      ref: fix/auth/platform-thread
      path: packages/aws_signature_v4

I'm still looking into the original issue. It seems there are multiple reports in the new Dart/Flutter versions around caught exceptions being reported as uncaught (dart-lang/sdk#53334). I'm wondering if that's related. I'll keep investigating and see what I can find.

@charlieforward9
Copy link
Author

charlieforward9 commented Aug 25, 2023

@dnys1 I appreciate you sharing the issue that may be causing this, I have subscribed to it. It is nice to get introduced to a lower level of the development process with a relevant issue at hand. The more ya know ...

With your PR, the dev.flutter.pigeon.NativeAuthPlugin.fetchAuthSession warning was gone ✅

Im still getting the original issue. I clicked continue repeatedly to pass through the issues. Now, I started getting this log from my BLoC library.

emit was called after an event handler completed normally.
This is usually due to an unawaited future in an event handler.
Please make sure to await all asynchronous operations with event handlers
and use emit.isDone after asynchronous operations before calling emit() to
ensure the event handler has not completed.

It seems that wrapping all my emit statements in if(!isClosed && !emit.isDone) fixed this issue, but with over 10 emit statements per BLoC, its definitely not a pleasant workaround. Thankfully it is only isolated to my AuthBloc. This likely is not relevant to Amplify, and would be likely resolved by the issue you linked above as well, but if you have any feedback, please enlighten me!

Thank you again for your continued support.

@dnys1
Copy link
Contributor

dnys1 commented Aug 29, 2023

Hi @charlieforward9, the fix for the pigeon warning has been released in v1.4.0.

I'm sorry to hear that the other issue is persisting. Please keep an eye on the Dart SDK issue. I will keep an eye out as well and look for any potential workarounds.

@dnys1 dnys1 added service-team and removed pending-community-response Pending response from the issue opener or other community members Investigating labels Aug 29, 2023
@charlieforward9
Copy link
Author

@dnys1 , it looks like the SDK team issued a patch release, detailed here.

I updated my flutter and Dart SDK, but it is still pausing my debugger. When I click continue, fetchAuthSession returns this:

 {
"isSignedIn": false,
"userSub": "AWSErrorResult<String, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
"userPoolTokens": "AWSErrorResult<CognitoUserPoolTokens, SignedOutException> {\n  \"exception\": {\n    \"message\": \"No user is currently signed in\"\n  },\n  \"stackTrace\": null\n}",
"credentials": "AWSErrorResult<AWSCredentials, SessionExpiredException> {\n  \"exception\": {\n    \"message\": \"The AWS credentials could not be retrieved\",\n    \"recoverySuggestion\": \"Invoke Amplify.Auth.signIn to re-authenticate the user\",\n    \"underlyingException\": \"NotAuthorizedException {\\n  message=Unauthenticated access is not supported for this identity pool.,\\n}\"\n  },\n  \"stackTrace\": \"#0      HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\\n<asynchronous suspension>\\n#1      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)\\n<asynchronous suspension>\\n\"\n}",
"identityId": "AWSErrorResult<String, SessionExpiredException> {\n  \"exception\": {\n    \"message\": \"The AWS credentials could not be retrieved\",\n    \"recoverySuggestion\": \"Invoke Amplify.Auth.signIn to re-authenticate the user\",\n    \"underlyingException\": \"NotAuthorizedException {\\n  message=Unauthenticated access is not supported for this identity pool.,\\n}\"\n  },\n  \"stackTrace\": \"#0      HttpOperation.deserializeOutput (package:smithy/src/http/http_operation.dart:312:7)\\n<asynchronous suspension>\\n#1      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)\\n<asynchronous suspension>\\n\"\n}"

Is there anything on the library side that needs to be updated with the new SDK release? I do not know what else to do on my side.

@dnys1
Copy link
Contributor

dnys1 commented Sep 15, 2023

Hi @charlieforward9, unfortunately the stable release only had a fix for the InternetAddress.lookup issue. The larger issue is fixed in main but is not being cherry-picked to stable. See the discussion here.

Can you try on Flutter master channel to see if that resolves the issue?

The fix is only so that the debugger doesn't pause. The response of fetchAuthSession will be the same, however. Are you saying the response from fetchAuthSession is not what you expect?

@charlieforward9
Copy link
Author

charlieforward9 commented Sep 15, 2023

@dnys1 thanks for the quick response. I am looking for a fix that will not make the debugger pause when there is an internal Amplify Auth Error, which seems to be part of the functionality of fetchAuthSession. I don't its response to be different.

I tried with the master channel and my debugger continues to pause. This is the channel I was using to begin with.

Here is my flutter --version

Flutter 3.14.0-14.0.pre.312 • channel master • https://github.com/flutter/flutter.git
Framework • revision 72b69f9449 (3 hours ago) • 2023-09-15 08:55:50 -0700
Engine • revision 45bc4307cd
Tools • Dart 3.2.0 (build 3.2.0-162.0.dev) • DevTools 2.28.0-dev.0

@charlieforward9
Copy link
Author

charlieforward9 commented Sep 15, 2023

The debugger only pauses when isSignedIn: false when I refresh the application

@dnys1
Copy link
Contributor

dnys1 commented Sep 18, 2023

Thanks for trying, @charlieforward9. Unfortunately, I haven't been able to reproduce this issue yet.

Would you be able to provide a minimal repro so I could take a look?

@dnys1 dnys1 added not-reproducible Issues that cannot be reproduced using the steps provided Investigating labels Sep 18, 2023
@Jordan-Nelson
Copy link
Member

@charlieforward9 - Are you still facing this issue? If so, are you able to provide a minimal reproduction?

@Jordan-Nelson Jordan-Nelson added the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Oct 12, 2023
@Jordan-Nelson Jordan-Nelson self-assigned this Oct 12, 2023
@charlieforward9
Copy link
Author

@Jordan-Nelson Yes, I just reran my auth code again and am still encountering this issue on sign-in. I am able to resume the application by clicking the continue button without an issue, and it only pauses in debug mode, nonetheless it is still a bug I am encountering. I will work on creating a minimal reproduction over the next few days.

Screen Shot 2023-10-19 at 6 10 28 PM

@Jordan-Nelson
Copy link
Member

@charlieforward9 Have you managed to create a minimal reproduction?

@iam-joel
Copy link

iam-joel commented Dec 5, 2023

@charlieforward9 were you able to find a workaround? I'm having the exact same issue. I'm on the latest amplify libs, flutter and dart sdk.

@haverchuck
Copy link
Contributor

@iam-joel Do you have a consistent reproduction for this?

@iam-joel
Copy link

iam-joel commented Dec 5, 2023

@haverchuck I'm having this issue consistently on debug mode when the "Refresh Token has expired" and when I use forceRefresh. I removed forceRefresh and everything works as expected.

Edit: I need to see what happens when the token expires. I do have a fallback strategy in the catch block. Getting off work right now, will update tomorrow.

@charlieforward9
Copy link
Author

@iam-joel I have not found a workaround to this issue in debug mode yet other than just clicking the continue button until it makes it past the error. I have been focused on other projects recently but plan to return to the project giving me this issue in Jan-Feb. If the issue persists till then and remains unsolved, I will attempt to create a reproducible sample around then.

@osehmathias
Copy link

Seeing a similar issue with datastore.

[ERROR:flutter/shell/common/shell.cc(1015)] The 'com.amazonaws.amplify/datastore' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

#4261

@Jordan-Nelson
Copy link
Member

@osehmathias This sounds like a different issue. If you open a new GitHub issue and fill out the issue template we can investigate it.

@iam-joel @charlieforward9 - Please let us know if you can create a minimal reproduction of this as we have been unable to reproduce this.

@Jordan-Nelson
Copy link
Member

I am going to close this issue since we have been unable to reproduce it with the info provided. If someone is able to provide a minimal reproduction of the issue or provide additional details on how to reproduce it than we can reopen this issue.

@Jordan-Nelson
Copy link
Member

We managed to reproduce a similar issue. For anyone still facing this, you can follow #4345

@charlieforward9
Copy link
Author

I can confirm that upgrading to ^1.6.3 fixed the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth Category not-reproducible Issues that cannot be reproduced using the steps provided pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.
Projects
None yet
Development

No branches or pull requests

6 participants