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

Failed host lookup: while using dart frog. #6

Closed
guccisekspir opened this issue Oct 3, 2023 · 14 comments
Closed

Failed host lookup: while using dart frog. #6

guccisekspir opened this issue Oct 3, 2023 · 14 comments

Comments

@guccisekspir
Copy link

guccisekspir commented Oct 3, 2023

Hello,

I was trying to implement dart firebase admin library to my dart:frog project. It is successfully initializing but when I try to do anything related firestore I get
Failed host lookup: 'metadata.google.internal'

I dont have any logic I am just calling on main.

Future<FirebaseAdminApp> init(InternetAddress ip, int port) async {
  final admin = FirebaseAdminApp.initializeApp(
    'gizemlikutucom',
    // This will obtain authentication informations from the environment
    Credential.fromApplicationDefaultCredentials(),
  );

  return admin;
}

Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
  FirebaseAdminApp admin = await init(ip, port);

  try {
    final firestore = Firestore(admin);
    DocumentSnapshot a = await firestore.collection("a").doc("b").get();

    print(a.data());
  } catch (e) {
    print(e);
  }

  return serve(handler, ip, port);
}

here the versions

environment:
  sdk: ">=3.0.0 <4.0.0"

dependencies:
  dart_firebase_admin: ^0.0.2
  dart_frog: ^1.0.0
  shelf_cors_headers: ^0.1.5
@Ehesp
Copy link
Member

Ehesp commented Oct 4, 2023

Are you getting this error in local development?

@guccisekspir
Copy link
Author

Yes!

@Ehesp
Copy link
Member

Ehesp commented Oct 5, 2023

Thanks - does this error throw when calling firestore, or when initializing the app?

@guccisekspir
Copy link
Author

initializing working well, it is about calling firestore. Get set etc. all functions throw this error.

@rrousselGit
Copy link
Collaborator

Do you maybe have some stracktrace and a more complete example? Ideally something we can run

Firestore is working fine for me, and there's no reference to metadata.google.internal in the source, so I'm not immediately sure where that error is from.

@guccisekspir
Copy link
Author

Okey I will try but is firestore working fine for you on dart frog project @rrousselGit ?

@rrousselGit
Copy link
Collaborator

Acutally I think I know what this endpoint is.
But I still need a stacktrace from you.

@guccisekspir
Copy link
Author

Here the stack trace

#0      IOClient.send (package:http/src/io_client.dart:94:7)
<asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:32)
<asynchronous suspension>
#2      MetadataServerAuthorizationFlow._getScopes (package:googleapis_auth/src/oauth2_flows/metadata_server.dart:89:22)
<asynchronous suspension>
#3      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#4      MetadataServerAuthorizationFlow.run (package:googleapis_auth/src/oauth2_flows/metadata_server.dart:63:21)
<asynchronous suspension>
#5      clientFromFlow (package:googleapis_auth/src/oauth2_flows/base_flow.dart:27:25)
<asynchronous suspension>
#6      clientViaMetadataServer (package:googleapis_auth/src/metadata_server_client.dart:43:5)
<asynchronous suspension>
#7      clientViaApplicationDefaultCredentials (package:googleapis_auth/auth_io.dart:95:10)
<asynchronous suspension>
#8      _FirestoreHttpClient._getClient (package:dart_firebase_admin/src/google_cloud_firestore/firestore.dart:176:24)
<asynchronous suspension>
#9      _FirestoreHttpClient.v1.<anonymous closure> (package:dart_firebase_admin/src/google_cloud_firestore/firestore.dart:188:11)
<asynchronous suspension>
#10     DocumentReader._fetchDocuments (package:dart_firebase_admin/src/google_cloud_firestore/document_reader.dart:50:23)
<asynchronous suspension>
#11     DocumentReader.get (package:dart_firebase_admin/src/google_cloud_firestore/document_reader.dart:21:5)
<asynchronous suspension>
#12     DocumentReference.get (package:dart_firebase_admin/src/google_cloud_firestore/reference.dart:223:20)
<asynchronous suspension>
#13     run (file:///Users/cagri/Documents/GitHub/gizemli_kutu_back/main.dart:29:26)
<asynchronous suspension>
#14     withHotreload.<anonymous closure> (package:shelf_hotreload/src/with_hotreload.dart:81:21)
<asynchronous suspension>
#15     withHotreload (package:shelf_hotreload/src/with_hotreload.dart:102:3)
<asynchronous suspension>

@rrousselGit
Copy link
Collaborator

I am not fully sure why yet, but that issue appears to be caused by logging in with the environment.
I'll see if I can update the source to get a better error message, and try a few things to see if I can reproduce it locally.

But for now, you could try logging in with a service-account.json file. That likely would work

@rrousselGit
Copy link
Collaborator

Alternatively, are you trying to use the emulator but maybe didn't start it?

@rrousselGit
Copy link
Collaborator

The weird thing is that it's googleapis_auth who's failing, not the Admin SDK itself. Maybe we should chat with them to see what could possibly cause this.

@rrousselGit
Copy link
Collaborator

I think I know:

You don't seem to be logged in. Therefore googleapis_auth fallbacks to reaching out to the google-cloud-only API for logging in – which fails since you're working locally.

You should have one of the following setup:

  • Platform.environment['GOOGLE_APPLICATION_CREDENTIALS']
  • on windows, %appdata%/gcloud/application_default_credentials.json
  • otherwise $HOME/.config/gcloud/application_default_credentials.json (with HOME env set!)

If none of these are true, you'll end-up with this error.

The error message is cryptic, but likely expected.

@rrousselGit
Copy link
Collaborator

Closing as this was answered. I raised a PR to improve the error message. It's only a matter of time before the message is more intuitive :)

@mafreud
Copy link
Contributor

mafreud commented Dec 31, 2023

Same issue here. I hope a better error message comes to this package.

Btw, authenticating with service account json works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants