cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

CLI Dart program hangs without terminating #110

Closed nullbtb closed 1 year ago

nullbtb commented 1 year ago

I'm trying to use firestore on a CLI program with Firedart 0.9.4. It works as expected, however it seems to hang in there for like 4 minutes if I call the "get" method for a collection reference. I'm guessing there's some connection that needs to be closed. However, I haven't found a way to achieve this or any references in the documentation.

import 'dart:io';

import 'package:firedart/firedart.dart';
import 'package:firedart/firestore/application_default_authenticator.dart';

Future<void> main() async {
  final projectId = Platform.environment['GOOGLE_PROJECT_ID'];
  assert(
    projectId != null,
    'GOOGLE_PROJECT_ID environment variable must be set.',
  );
  assert(
    Platform.environment.containsKey('GOOGLE_APPLICATION_CREDENTIALS'),
    'GOOGLE_APPLICATION_CREDENTIALS environment variable must be set. ',
  );

  try {
    final auth = ApplicationDefaultAuthenticator(useEmulator: false);
    final client = Firestore(projectId!, authenticator: auth.authenticate);
    final ref = client.collection('object_entities');
    final documents = await ref.get(); // Problem line
    print('Done.');
  } on Exception catch (e) {
    print('Error: $e');
  }
}
cachapa commented 1 year ago

Honestly, I have the same issue in the example app, and couldn't find the cuprit which is why I ended up dropping an exit(0) at the end.

If you want to go down the rabbit hole and find a solution, I'd appreciate a PR :-)

nullbtb commented 1 year ago

Hi Daniel, I made a PR for this, please give it a shot. From my testing it allows the program to exist successfully now.

cachapa commented 1 year ago

Fixed by #111