aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 248 forks source link

datastore sent a message from native to Flutter on a non-platform thread #4261

Closed osehmathias closed 4 months ago

osehmathias commented 10 months ago

Description

After setting up datastore, this error is printed in the console on start.

[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.

Categories

Steps to Reproduce

  1. Add datastore with selective sync
  2. Flutter run

Using:

amplify_datastore: ^1.6.0

Screenshots

No response

Platforms

Flutter Version

3.16.4

Amplify Flutter Version

1.6.1

Deployment Method

Amplify CLI

Schema

No response

khatruong2009 commented 10 months ago

Hi @osehmathias, thank you for submitting this issue. We will be looking into this soon.

osehmathias commented 10 months ago

Thank you @khatruong2009 - let me know how I can help.

haverchuck commented 10 months ago

@osehmathias Could you share your graphql schema and an example of the API invocation that is triggering this? Are you seeing this when the app goes into the background?

(See #4262 )

osehmathias commented 10 months ago

@haverchuck - I am not sure I can share the full schema in a public channel due to the nature of this app. However, most tables have haveMany / belongsTo relationships, auth rules based on groups, and indices.

I start the sync after auth is confirmed in the following way

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final clientId = await _fetchUserId();
  currentUserId = clientId;
  await _configureAmplify(clientId);
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((value) => runApp(
            const ProviderScope(
              child: AuthWrapper(),
            ),
          ));
}

Future<void> _configureAmplify(String? clientId) async {
  final datastorePlugin = AmplifyDataStore(
    modelProvider: ModelProvider.instance,
    syncExpressions: [
      DataStoreSyncExpression(
        Client.classType,
           Client.ID.eq(clientId!).or(Client.CLIENTID.eq(clientId))
      ),
      ....

I have tried creating an app from scratch (e.g. flutter create test), then adding Amplify to it in the way described here: https://aws.amazon.com/getting-started/hands-on/build-flutter-mobile-app-part-one/

This message occurs on startup. See below:

osehmathias@Osehs-MacBook-Air mobile % flutter run
Launching lib/main.dart on Oseh  in debug mode...
Automatically signing iOS for device deployment using specified development team
in Xcode project: 83F2Q38TKB
Running Xcode build...
 └─Compiling, linking and signing...                         4.9s
Xcode build done.                                           23.9s
You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If
access is not allowed, you can change this through your Settings > Privacy & Security >
Automation.
[ERROR:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm(42)] Using the Impeller rendering backend.
[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.
Installing and launching...                                        26.0s
Syncing files to device Oseh ...                                   323ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Oseh  is available at: http://127.0.0.1:51580/yWlRZJpjdVM=/
The Flutter DevTools debugger and profiler on Oseh  is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:51580/yWlRZJpjdVM=/
harrynguyenangle commented 10 months ago

my case is 'com.amazonaws.amplify/datastore_observe_events' full error description

The 'com.amazonaws.amplify/datastore_observe_events' 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.
yoshi23 commented 8 months ago

Getting the same error with Datastore: [ERROR:flutter/shell/common/shell.cc(1015)] The 'com.amazonaws.amplify/datastore_observe_events' 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.

Equartey commented 7 months ago

Hey all, thanks for bringing this to our attention. We have been able to reproduce this and are investigating.

We will provide an update when we can.

Jordan-Nelson commented 6 months ago

I am going to label this a bug since we were able to reproduce this. We will continue to investigate if these can be safely ignored and will post here when we have an update.

Equartey commented 5 months ago

Hi @osehmathias, this was fixed on iOS in Amplify Flutter 2.1.0.

I have not seen the error message on Android yet. If you're viewing it on Android, could you give us the log message so we can address it there as well?

tyllark commented 4 months ago

Hey @osehmathias we are closing this issue due to inactivity. If you experience this issue again please open another issue.