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

AmplifyException on Datastore re-initialization #5793

Open
2 of 14 tasks
veeramneni opened this issue Jan 6, 2025 · 5 comments
Open
2 of 14 tasks

AmplifyException on Datastore re-initialization #5793

veeramneni opened this issue Jan 6, 2025 · 5 comments
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category

Comments

@veeramneni
Copy link

veeramneni commented Jan 6, 2025

Description

I have Amplify setup for Auth, API and Datastore. They are configured without an issue on app launch. However, upon killing the app and relaunching, amplify configuration fails with below error.

AmplifyException{message=User-Agent was already configured successfully., cause=null, recoverySuggestion=User-Agent is configured internally during Amplify configuration. This method should not be called externally.}

I am not sure where it's picking User-agent from. I understand it is set automatically by Amplify. Amplify.isConfigured is indeed false before reconfiguration. So I know it is not configured before trying again.

Any ideas or thoughts are much appreciated

If it helps, the exception is being triggered in amplify_datastore.dart at this code

try {
final nativeBridge = NativeAmplifyBridge();
await nativeBridge.configure(
Amplify.version,
jsonEncode(config.toJson()),
);
} on PlatformException catch (e) {
if (e.code == 'AmplifyException') {

    throw AmplifyException.fromMap(
      Map<String, String>.from(e.details as Map),
    );
    return;
  }

Categories

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

Steps to Reproduce

  1. Create an Amplify flutter project with Auth, API and Datastore
  2. Configure it with Amplify.configure
  3. Kill and relaunch the app to re-configure Amplify
  4. Watch for configuration exception.

Screenshots

No response

Platforms

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

Flutter Version

3.34.4

Amplify Flutter Version

2.5.0

Deployment Method

Amplify Gen 2

Schema

No response

@github-actions github-actions bot added pending-triage This issue is in the backlog of issues to triage pending-maintainer-response Pending response from a maintainer of this repository labels Jan 6, 2025
@tyllark
Copy link
Member

tyllark commented Jan 6, 2025

Hello @veeramneni, this sounds like a duplicate of this issue, please let me know if you agree. Internally we are not handling an exception properly, which is causing this exception to be thrown rather than logging and failing silently. We have a PR open with a fix, but we are waiting for a test to be fixed prior to merging.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Jan 6, 2025
@veeramneni
Copy link
Author

Thank's for your response. Yes, it is indeed the same issue and we can ignore this exception on our end. However, Datastore is not able to successfully start the sync after this. Even after stop, clear and start, I see hub event stuck in 'Outbox' status. I neither see any configuration error nor other event's. Am I missing something?(Auth and API are fine)

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Jan 7, 2025
@tyllark
Copy link
Member

tyllark commented Jan 7, 2025

DataStore's internal Auth configuration breaks with this exception. Any DataStore API calls afterwards will make the changes locally and they will remain your Outbox until you restart the app with a properly configured DataStore. If you want to verify these changes fully resolve your issue you can add a pubspec_overrides.yaml file to your project with the following content:

dependency_overrides:
  amplify_datastore:
    git:
      url: https://github.com/aws-amplify/amplify-flutter.git
      ref: fix/datastore_android_multi-configure
      path: packages/amplify_datastore
      fetch: fix/datastore_android_multi-configure

Just remember to delete these overrides afterwards!

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Jan 7, 2025
@veeramneni
Copy link
Author

Thanks again! This does safely ignore exception but the exception itself is resulting when the app is restarted. So upon original launch plugin gets initialized like so:

I/amplify:flutter:datastore( 8139): Added Auth plugin I/amplify:flutter:datastore( 8139): Added API plugin I/amplify:flutter:datastore( 8139): Unhandled DataStoreHubEvent: SUCCEEDED I/amplify:flutter:datastore( 8139): com.amplifyframework.core.category.CategoryInitializationResult@417428a I/amplify:flutter:datastore( 8139): Established a new stream form flutter com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter$$ExternalSyntheticLambda1@a6de9d8

Once app is killed and restarted, it appears like native android is keeping part of amplify configuration alive(possibly because of background services?). So, the exception from your branch does safely ignore reconfiguration error, however Amplify Datastore is not properly configured. Is there a way to force clear any amplify configuration lingering in the background so Amplify gets re-initialized properly?

This is how the relaunch log looks like. As you can see, plugins are not initialized again and Datastore is not syncing as expected.

I/amplify:flutter:datastore( 8139): Initiated DataStore plugin I/amplify:flutter:datastore( 8139): Initiated DataStore plugin I/amplify:flutter:datastore( 8139): Established a new stream form flutter com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter$$ExternalSyntheticLambda1@7aa64ce

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Jan 8, 2025
@tyllark
Copy link
Member

tyllark commented Jan 8, 2025

For internal testing purposes we have an Amplify.reset() call, but this is not intended for customer use and I don't see any MessageChannels that would extend this reset to the Android native layer. I'm going to mark this issue as a bug since this use case was not accounted for in the provided PR. We will investigate and respond here when we have an update.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Jan 8, 2025
@tyllark tyllark added bug Something is not working; the issue has reproducible steps and has been reproduced pending-maintainer-response Pending response from a maintainer of this repository labels Jan 8, 2025
@github-actions github-actions bot removed the pending-triage This issue is in the backlog of issues to triage label Jan 8, 2025
@tyllark tyllark added datastore Issues related to the DataStore Category and removed pending-maintainer-response Pending response from a maintainer of this repository labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category
Projects
None yet
Development

No branches or pull requests

2 participants