Skip to content

[google_sign_in_web] _initCalled completed twice #167410

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

Open
jtmcdole opened this issue Apr 18, 2025 · 4 comments
Open

[google_sign_in_web] _initCalled completed twice #167410

jtmcdole opened this issue Apr 18, 2025 · 4 comments
Labels
p: google_sign_in The Google Sign-In plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@jtmcdole
Copy link
Member

While debugging the dashboard, I noticed Bad state: Future already completed. In initWithParams, the _initState variable is set but not captured locally. If initWithParams is called twice (my own bug), the completer gets overridden and then completed twice.

Potential solutions:

  • capture the completer; before completing, test if capture != _initState, complete or complete with an error.
  • initWithParams checks if _initState exists and awaits it before calling itself again

Meanwhile I'll still try to find out why our code is calling this twice...

stack:

Bad state: Future already completed
main.dart.mjs:59     at module0.Error._throwWithCurrentStackTrace (http://localhost:8080/main.dart.wasm:wasm-function[987]:0x178a1d)
    at module0._AsyncCompleter.complete (body) (http://localhost:8080/main.dart.wasm:wasm-function[984]:0x1789a1)
    at module0._AsyncCompleter.complete (unchecked entry) (http://localhost:8080/main.dart.wasm:wasm-function[1812]:0x188962)
    at module0.GoogleSignInPlugin.initWithParams inner (http://localhost:8080/main.dart.wasm:wasm-function[29305]:0x3a9d70)
    at module0._awaitHelper closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:104:5 (http://localhost:8080/main.dart.wasm:wasm-function[1903]:0x189ded)
    at module0.closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:104:5 trampoline (http://localhost:8080/main.dart.wasm:wasm-function[1908]:0x189e87)
    at module0._RootZone.runUnary (http://localhost:8080/main.dart.wasm:wasm-function[1284]:0x17fc5a)
    at module0._FutureListener.handleValue (body) (http://localhost:8080/main.dart.wasm:wasm-function[1291]:0x17ff42)
@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team platform-web Web applications specifically p: google_sign_in The Google Sign-In plugin package flutter/packages repository. See also p: labels. fyi-ecosystem For the attention of Ecosystem team team-web Owned by Web platform team and removed in triage Presently being triaged by the triage team labels Apr 21, 2025
@stuartmorgan-g stuartmorgan-g added the triaged-ecosystem Triaged by Ecosystem team label Apr 22, 2025
@flutter-triage-bot flutter-triage-bot bot removed fyi-ecosystem For the attention of Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Apr 24, 2025
@jbuijgers
Copy link

Can confirm, as far as it helps, here is my stacktrace.

Uncaught (in promise) DartError: Bad state: Future already completed
    at Object.throw_ [as throw] (errors.dart:307:3)
    at async._AsyncCompleter.new.complete (future_impl.dart:84:31)
    at google_sign_in_web.dart:173:5
    at async_patch.dart:622:19
    at async_patch.dart:647:23
    at async_patch.dart:593:31
    at _RootZone.runUnary (zone.dart:1849:54)
    at async._FutureListener.thenAwait.handleValue (future_impl.dart:208:18)
    at handleValueCallback (future_impl.dart:932:44)
    at _Future._propagateToListeners (future_impl.dart:961:13)
    at [_completeWithValue] (future_impl.dart:712:5)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:792:7)
    at Object._microtaskLoop (schedule_microtask.dart:40:11)
    at _startMicrotaskLoop (schedule_microtask.dart:49:5)
    at async_patch.dart:186:7

Code, using auto_router for @RoutePage(). Example is largely from firebase_ui_auth repo.

@RoutePage()
class SigninPage extends StatelessWidget {
  const SigninPage({super.key});

  @override
  Widget build(BuildContext context) {
    print('SigninPage build');

    return AuthStateListener<OAuthController>(
      child: OAuthProviderButton(
        provider: GoogleProvider(clientId: Common.googleClientId),
      ),
      listener: (oldState, newState, ctrl) {
        if (newState is SignedIn) {
          Navigator.pushReplacementNamed(context, '/');
        }

        return null;
      },
    );
  }
}

To reproduce

  1. flutter run -d web-server
  2. In browser, open console
  3. Refresh until error pops up
    a. Error wil almost always pop-up, might help to hot restart and refresh.
    b. No difference between refresh with/without cache (spotted)

Sidenotes
The console always has a bunch of lines (4) starting with '[GSI_LOGGER]: ....', whenever these come first, and my own debug messages come after, no error is shown. If my own debug messages come first, then the console will print the above mentioned error.

@mdebbar mdebbar added P2 Important issues not at the top of the work list triaged-web Triaged by Web platform team labels May 21, 2025
@mdebbar
Copy link
Contributor

mdebbar commented May 21, 2025

@jtmcdole are you still looking into this issue?

@jtmcdole
Copy link
Member Author

@mdebbar - I'm not actively looking into this; I filed the bug so it wouldn't get lost.

I also have problems with this plugin which cannot tell that the pop up hasn't closed and thus cannot sign in.

@jbuijgers
Copy link

In packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart:173-175, the following has been working so far for me.

if (!_initCalled!.isCompleted) {
  _initCalled!.complete(); // Signal that `init` is fully done.
}

This solves the error, but not the root cause, although the latter seems to be a bit out of (project) scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: google_sign_in The Google Sign-In plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

No branches or pull requests

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy