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

issue with "User-Agent was already configured successfully" #5244

Closed
2 of 14 tasks
mobiletoly opened this issue Aug 5, 2024 · 9 comments
Closed
2 of 14 tasks

issue with "User-Agent was already configured successfully" #5244

mobiletoly opened this issue Aug 5, 2024 · 9 comments
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category

Comments

@mobiletoly
Copy link

Description

This issue is related to amplify_datastore.dart file.

in method:

@override
  Future<void> configure({
    AmplifyOutputs? config,
    required AmplifyAuthProviderRepository authProviderRepo,
  }) async {
...
}

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),
        );
    ...

so this line Map<String, String>.from(e.details as Map) throws error (type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast) because e.details can be null.

in my case PlatformException contains this information

PlatformException(
  AmplifyException, 
  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.},
  null,
  null
)

(as you can see e.details field is null there)

I would suggest to ignore this "User-Agent was already configured successfully" error, because for example in my case I'm initializing Amplify from the main UI thread, but there is also a possibility that some separate isolate is launched and it tries to initialize Amplify as well (have to deal with background services). Since there is no way to detect from one isolate that Amplify was already configured in another isolate - I end up having this issue.

Categories

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

Steps to Reproduce

  1. Register Amplify with DataStore plugin in main isolate
  2. Register Amplify with DataStore plugin in different isolate

Screenshots

No response

Platforms

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

Flutter Version

3.24.0-0.2.pre

Amplify Flutter Version

3.2.0

Deployment Method

Amplify CLI

Schema

No response

@tyllark
Copy link
Member

tyllark commented Aug 6, 2024

Hi @mobiletoly, thanks for taking the time to submit this issue. We will investigate this isolate configuration behavior and update you as we can.

@tyllark
Copy link
Member

tyllark commented Aug 7, 2024

Hi @mobiletoly, I wanted to note that we do not officially support Amplify in multiple isolates, but I was able to reproduce the issue you mentioned. We should not be throwing the type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast exception. There is already logic in place to silently log AmplifyAlreadyConfiguredExceptions, but it is not being hit due to additional exception handling downstream returning an unexpected exception that we do not handle properly. I'm marking this as a bug and we will get back to you when we have a fix.

@tyllark tyllark added datastore Issues related to the DataStore Category bug Something is not working; the issue has reproducible steps and has been reproduced labels Aug 7, 2024
@mohammedhashim790
Copy link

Hi @tyllark , Any updates on the following issue. Noticed this while initialising Amplify in Isolates. Quick update would be of great help.

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Oct 23, 2024
@ekjotmultani
Copy link
Member

Hi @mohammedhashim790 , unfortunately we do not have any updates or a timeline for this fix at this time. We have an open issue #5302 for tracking isolate support, so please give these issues a thumbs up to help us determine an interest in these features.

@HarkerTech
Copy link

HarkerTech commented Nov 7, 2024

Hi, we have also encountered this error on amplify_datastore v2.5.0 when hot reloading as well as when activities are destroyed/recreated on Android (replicated by enabling "Don't keep activities").

As a temporary workaround we have created a fork with an additional check to ignore this message when seen. This does appear to then hit another issue when the activity is destroyed (#5458) but not sure if it is related.

...
 if (e.code == 'AmplifyException') {
        if (e.message != null &&
            e.message!
                .contains("User-Agent was already configured successfully.")) {
          logger.debug(
              'Ignoring Amplify Native User-Agent already configured exception');
          return;
        }
        throw AmplifyException.fromMap(
          Map<String, String>.from(e.details as Map),
        );
      } else if (e.code == 'AmplifyAlreadyConfiguredException') {
        logger.debug('Ignoring Amplify Native already configured exception');
        return;
...

From our testing with previous amplify_datastore versions it appears this was introduced between amplify_datastore v2.1.0 and v2.2.1.

@NikaHsn
Copy link
Member

NikaHsn commented Nov 18, 2024

@HarkerTech thanks for providing additional information. we will look into this and provide updates as we have them.

@tyllark
Copy link
Member

tyllark commented Jan 14, 2025

Hi @mobiletoly @mohammedhashim790 @HarkerTech, a fix for this issue was just released for amplify_datastore 2.6.0. Please update your packages and let us know if you have any issues!

@tyllark tyllark 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 Jan 14, 2025
@mohammedhashim790
Copy link

Hi @tyllark , Thanks for the update!

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Jan 22, 2025
@tyllark tyllark removed the pending-maintainer-response Pending response from a maintainer of this repository label Jan 23, 2025
@github-actions github-actions bot removed the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Jan 30, 2025
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

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

6 participants