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

Сrash after completing a workmanager task #5191

Open
3 of 14 tasks
eslavyansky opened this issue Jul 22, 2024 · 2 comments
Open
3 of 14 tasks

Сrash after completing a workmanager task #5191

eslavyansky opened this issue Jul 22, 2024 · 2 comments
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced push notifications

Comments

@eslavyansky
Copy link

eslavyansky commented Jul 22, 2024

Description

After completing the workmanager task, the application crashes when receiving a push notification.

D/AmplifyAuthCognitoPlugin( 7925): onAttachedToEngine

I/flutter ( 7925): executeTask
I/WM-WorkerWrapper( 7925): Worker result SUCCESS for Work [ id=2457b878-41f6-4e94-a6f7-571d215f354b, tags={ dev.fluttercommunity.workmanager.BackgroundWorker } ]
D/AmplifyAuthCognitoPlugin( 7925): onDetachedFromEngine
D/AmplifyAuthCognitoPlugin( 7925): [cancelCurrentOperation] Canceling with state: signInResult=null, signOutResult=null

D/AndroidRuntime( 7925): Shutting down VM
E/AndroidRuntime( 7925): FATAL EXCEPTION: main
E/AndroidRuntime( 7925): Process: com.example.app, PID: 7925
E/AndroidRuntime( 7925): java.lang.NullPointerException
E/AndroidRuntime( 7925): 	at com.amazonaws.amplify.amplify_push_notifications.PushNotificationFirebaseMessagingService.handleMessageReceived$lambda$3(PushNotificationFirebaseMessagingService.kt:72)
E/AndroidRuntime( 7925): 	at com.amazonaws.amplify.amplify_push_notifications.PushNotificationFirebaseMessagingService.$r8$lambda$3gv-VezmiX7SI0LpF2RU5uWz5uo(Unknown Source:0)
E/AndroidRuntime( 7925): 	at com.amazonaws.amplify.amplify_push_notifications.PushNotificationFirebaseMessagingService$$ExternalSyntheticLambda1.run(Unknown Source:6)
E/AndroidRuntime( 7925): 	at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime( 7925): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7925): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 7925): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 7925): 	at android.app.ActivityThread.main(ActivityThread.java:8144)
E/AndroidRuntime( 7925): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7925): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:573)
E/AndroidRuntime( 7925): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1023)

Categories

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

Steps to Reproduce

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    safePrint("executeTask");
    return Future.value(true);
  });
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  final auth = AmplifyAuthCognito();
  final pushPlugin = AmplifyPushNotificationsPinpoint();
  await Amplify.addPlugins([auth, pushPlugin]);
  await Amplify.configure(amplifyconfig);

  Amplify.Notifications.Push.onTokenReceived.listen((event) {
    safePrint("onTokenReceived: $event");
  });

  Workmanager().initialize(callbackDispatcher, isInDebugMode: true);

  // no error if you comment this
  Workmanager().registerOneOffTask("test", "test");

  runApp(const MyApp());
}

Screenshots

No response

Platforms

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

Flutter Version

3.22.3

Amplify Flutter Version

2.3.0

Deployment Method

Custom Pipeline

Schema

No response

@Jordan-Nelson Jordan-Nelson added pending-triage This issue is in the backlog of issues to triage push notifications labels Jul 22, 2024
@Jordan-Nelson
Copy link
Member

Hello @eslavyansky - Thanks for opening the issue. We will look into this. I will let you know if we need more info.

@Jordan-Nelson Jordan-Nelson added the to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided label Jul 23, 2024
@tyllark
Copy link
Member

tyllark commented Aug 15, 2024

Hello @eslavyansky I was able to reproduce the issue you described. WorkManager is stopping the Flutter engine which deinitializes all of our native plugins as you can see from this stack trace:

at com.amazonaws.amplify.amplify_push_notifications.StreamHandlers$Companion.deInit(PushNotificationEventsStreamHandler.kt:199)
at com.amazonaws.amplify.amplify_push_notifications.AmplifyPushNotificationsPlugin.onDetachedFromEngine(AmplifyPushNotificationsPlugin.kt:133)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:272)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:280)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:288)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:123)
at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:470)
at dev.fluttercommunity.workmanager.BackgroundWorker.stopEngine$lambda$3(BackgroundWorker.kt:143)
at dev.fluttercommunity.workmanager.BackgroundWorker.$r8$lambda$YX_kSwcT9UnNdOdlpnrG92Wu8AY(Unknown Source:0)
at dev.fluttercommunity.workmanager.BackgroundWorker$$ExternalSyntheticLambda2.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

We currently don't support amplify isolates, but I created a feature request to support isolates and included a section for workmanager. However we shouldn't be crashing the app when the Flutter Engine is stopped, so I will mark this as a bug so we can add proper error handling and logging for this situation. Please note that push notifications still will not work since the Flutter engine will still be stopped, but the app shouldn't crash. We will get back to you once the error handling is implemented.

@tyllark tyllark added bug Something is not working; the issue has reproducible steps and has been reproduced and removed to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided pending-triage This issue is in the backlog of issues to triage labels Aug 15, 2024
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 push notifications
Projects
None yet
Development

No branches or pull requests

3 participants