GoogleCloudPlatform / recaptcha-enterprise-flutter

Apache License 2.0
23 stars 8 forks source link

Issue while using the recaptcha-enterprise-flutter package in conjunction with a foreground service in my Flutter app #11

Closed Samuel310 closed 10 months ago

Samuel310 commented 1 year ago

Hello, I hope this message finds you well. I wanted to reach out to you regarding an issue I’ve encountered while using the recaptcha-enterprise-flutter package in conjunction with a foreground service in my Flutter app.

Issue Description: Foreground service is crashed when app is killed after initialising the RecaptchaEnterprise client by calling await RecaptchaEnterprise.initClient(siteKey);. But the foreground service is not crashed and worked as expected when await RecaptchaEnterprise.initClient(siteKey); is commented out.

Steps to Reproduce:

  1. used recaptcha_enterprise_flutter: ^18.2.1
  2. flutter and dart versions Flutter 3.3.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision eb6d86ee27 (9 months ago) • 2022-10-04 22:31:45 -0700 Engine • revision c08d7d5efc Tools • Dart 2.18.2 • DevTools 2.15.0
  3. sample code
    
    void mainApp() {
    WidgetsFlutterBinding.ensureInitialized();
    runApp(const MyApp());
    }

class MyApp extends StatelessWidget { const MyApp({super.key});

@override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData.dark().copyWith( scaffoldBackgroundColor: Colors.white, ), debugShowCheckedModeBanner: false, home: const HomeScreen(), ); } }

class HomeScreen extends StatefulWidget { const HomeScreen({super.key});

@override State createState() => _HomeScreenState(); }

class _HomeScreenState extends State {

void _initializeRecaptchaClient({required String siteKey}) async { try { bool res = await RecaptchaEnterprise.initClient(siteKey); log("res : $res"); } catch (err) { log('Caught exception on initializeRecaptchaClient: $err'); } }

@override void initState() { super.initState(); _initializeRecaptchaClient(siteKey: ""); }

@override void dispose() { super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("SERVICES"), ), body: Column( children: [ ElevatedButton( onPressed: () async { // Wrote a separate plugin to handle foreground services in java. MyForegroundServiceHelper.instance.startService(); }, child: const Text("Start SOS"), ), ], ), ); } }


**Log**:

D/MyForegroundServicePlugin( 7124): onDetachedFromActivity: called D/MyForegroundServicePlugin( 7124): onDetachedFromEngine: *** Called W/cr_ChildProcessConn( 7124): onServiceDisconnected (crash or killed by oom): pid=7282 bindings:W S E/chromium( 7124): [ERROR:aw_browser_terminator.cc(156)] Renderer process (7282) crash detected (code -1). E/chromium( 7124): [ERROR:aw_browser_terminator.cc(112)] Render process (7282) kill (OOM or update) wasn't handed by all associated webviews, killing application. Lost connection to device.



I would appreciate your support in investigating this issue further and providing guidance on how to handle the scenario.
Thank you for your attention to this matter, and I look forward to your response. Please feel free to reach out if you need any additional information.
mcorner commented 1 year ago

Interesting. We haven't tried running it in a service. Is there a use case for doing that? For lots of reasons we would recommend running this as part of your main application.

It sounds a bit like this report also: https://github.com/pichillilorenzo/flutter_inappwebview/issues/1316

Samuel310 commented 1 year ago

I have initialised recaptcha client inside the flutter application, its not inside the service. You can see the code i mentioned above. Steps:

  1. initialised recaptcha client in the main application. (inside initState).
  2. Started a foreground service on a button click after the recaptcha client is initialized in the main application.
  3. When the service is running in foreground i killed the app and got that error.

I'm not sure what's the cause of this error but if i don't initialise the recaptcha client the app wont crash. And I checked the bug report which you mentioned, i'm not using flutter_inappwebview plugin in my flutter app. The only plugin i'm using in my app is recaptcha-enterprise-flutter as of now.

mcorner commented 1 year ago

Got it. I have an idea what the problem may be, but it is likely an issue in the underlying sdk. We will look into it.

mcorner commented 1 year ago

Internal bug reference: b/289537266

mcorner commented 1 year ago

@Samuel310 Would it be possible to get a full example of the failure? I want to see how you are using MyForegroundServiceHelper etc. Thanks!

mcorner commented 10 months ago

obsolete