-
Notifications
You must be signed in to change notification settings - Fork 251
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
Comments
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 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. |
@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 |
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 |
Does this only happen when performing a hot restart? |
@dnys1 Thank you for your help.
No, when I do a fresh start with the debugger, it will pause... Debug Console LogLaunching 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. 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) 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 DataStorePlugin successfully initialized [log] Ending timeout timer [log] Attempting auto auth I have my entire |
@dnys1 I decided to use Auth Hub Events to work around 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
When I run this, my debugger will pause on Amplify.Auth.signIn. If I click However, if I hot restart it, I get this: Error Logpackage: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.completeLoginFurthermore, 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:
|
Hi @charlieforward9, thank you for the continued investigation. A few questions:
Regarding the two suspicious log messages:
This seems like a bug in our code which I will address.
This one can be safely ignored. I will investigate the possibility of removing it, but it is not harmful. |
Only
This error occurs when it is launched for the first time, AND when it is hot restarted. It throws when I run
Thank you. 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 |
This comment was marked as resolved.
This comment was marked as resolved.
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. |
@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 Im still getting the original issue. I clicked
It seems that wrapping all my emit statements in Thank you again for your continued support. |
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 , 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:
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. |
Hi @charlieforward9, unfortunately the stable release only had a fix for the Can you try on Flutter 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? |
@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 Here is my
|
The debugger only pauses when |
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? |
@charlieforward9 - Are you still facing this issue? If so, are you able to provide a minimal reproduction? |
@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. |
@charlieforward9 Have you managed to create a minimal reproduction? |
@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. |
@iam-joel Do you have a consistent reproduction for this? |
@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. |
@iam-joel I have not found a workaround to this issue in debug mode yet other than just clicking the |
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. |
@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. |
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. |
We managed to reproduce a similar issue. For anyone still facing this, you can follow #4345 |
I can confirm that upgrading to |
Description
This is my Amplify function:
and here is where I call it:
when I run my application, it crashes, pausing the main isolate, and showing this call stack in the 'Run & Debug' tab.
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 objectthe 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
Steps to Reproduce
No response
Screenshots
No response
Platforms
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
The text was updated successfully, but these errors were encountered: