firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

πŸ› [cloud_firestore] Operation never completes when setting host to local for emulator - iOS #4413

Closed tapizquent closed 3 years ago

tapizquent commented 3 years ago

Bug report

Describe the bug When working with firestore emulator and setting the host to localhost, the operations performed never complete.

Steps to reproduce

Steps to reproduce the behavior:

  1. Using any Flutter application, set the setting of Firestore as follows:
    
    String host = Platform.isAndroid ? '10.0.2.2:8080' : 'localhost:8080';

FirebaseFirestore.instance.settings = Settings( host: host, sslEnabled: false, persistenceEnabled: false, );

2. Start firebase firestore emulator `firebase emulators:start --only firestore`
3. Run any write operation such as `await FirebaseFirestore.instance.collection('test').doc().set({'test':'non-working'})`
4. See error or incorrect behavior. The operation never completes, neither fails nor returns. It just stays there.

### Expected behavior

The data should be written to the emulator.

---

## Additional context

Mind you that this is working if we remove the Settings configuration and leave it to use the real database.

---

### Flutter doctor

Run `flutter doctor` and paste the output below:

<details><summary>Click To Expand</summary>

[βœ“] Flutter (Channel stable, 1.22.5, on macOS 11.0.1 20B50 darwin-x64, locale en-US) β€’ Flutter version 1.22.5 at /Users/josetapizquent/Projects/Tools/flutter β€’ Framework revision 7891006299 (6 days ago), 2020-12-10 11:54:40 -0800 β€’ Engine revision ae90085a84 β€’ Dart version 2.10.4

[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /Users/josetapizquent/Library/Android/sdk β€’ Platform android-30, build-tools 29.0.3 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 12.2) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 12.2, Build version 12B45b β€’ CocoaPods version 1.9.1

[βœ“] Android Studio (version 3.6) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin version 45.1.1 β€’ Dart plugin version 192.8052 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[βœ“] VS Code (version 1.52.0) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.17.0

[βœ“] Connected device (1 available) β€’ TapPhone (mobile) β€’ 00008020-000E58220E99002E β€’ ios β€’ iOS 14.2

β€’ No issues found!


</details>

---

### Flutter dependencies

Run `flutter pub deps -- --style=compact` and paste the output below:

<details><summary>Click To Expand</summary>

Dart SDK 2.10.4 Flutter SDK 1.22.5 icay 1.0.0+2

dependencies:

dev dependencies:

transitive dependencies:


markusaksli-nc commented 3 years ago

I can't reproduce this on the latest master 1.26.0-2.0.pre.64 with cloud_firestore: ^0.14.4.

flutter doctor -v ``` [√] Flutter (Channel master, 1.26.0-2.0.pre.64, on Microsoft Windows [Version 10.0.19041.685], locale et-EE) β€’ Flutter version 1.26.0-2.0.pre.64 at C:\Development\flutter_master β€’ Framework revision 9ff4326e1f (4 hours ago), 2020-12-17 06:19:05 +0000 β€’ Engine revision 6edb402ee4 β€’ Dart version 2.12.0 (build 2.12.0-157.0.dev) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) β€’ Android SDK at C:\Users\marku\AppData\Local\Android\sdk β€’ Platform android-30, build-tools 30.0.2 β€’ Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) β€’ All Android licenses accepted. [√] Chrome - develop for the web β€’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7) β€’ Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community β€’ Visual Studio Community 2019 version 16.7.30621.155 β€’ Windows 10 SDK version 10.0.18362.0 [√] Android Studio (version 4.1.0) β€’ Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283 β€’ Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] IntelliJ IDEA Ultimate Edition (version 2020.3) β€’ IntelliJ at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\203.5981.155 β€’ Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart [√] Connected device (4 available) β€’ sdk gphone x86 arm (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 11 (API 30) (emulator) β€’ Windows (desktop) β€’ windows β€’ windows-x64 β€’ Microsoft Windows [Version 10.0.19041.685] β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 87.0.4280.88 β€’ Edge (web) β€’ edge β€’ web-javascript β€’ Microsoft Edge 87.0.664.60 β€’ No issues found! ```
Code sample ```dart import 'dart:io'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); FirebaseApp app = await Firebase.initializeApp(); assert(app != null); String host = Platform.isAndroid ? '10.0.2.2:8080' : 'localhost:8080'; FirebaseFirestore.instance.settings = Settings( host: host, sslEnabled: false, persistenceEnabled: false, ); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Material App', theme: ThemeData.dark(), home: Scaffold( appBar: AppBar( title: const Text('Sample'), ), body: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ RaisedButton( child: const Text("Set"), onPressed: () async { print('start'); await FirebaseFirestore.instance.collection('test').doc('testDoc').set({'test': 'non-working'}).catchError((e,s) => print('$e\n$s')); print('end'); }, ), RaisedButton( child: const Text("Get"), onPressed: () async { print('start'); var doc = await FirebaseFirestore.instance.collection('test').doc('testDoc').get(); print(doc.data()); }, ), ], ), ), ); } } ```

Can you reproduce this with this code sample? What version of the firebase CLI are you using? Thank you

tapizquent commented 3 years ago

Unfortunately this does not work. I replaced my whole main.dart with your code sample, and as I previously mentioned, it prints start and then stays there. Nothing gets written to the database and end does not print.

I am currently on the latest stable channel as I cannot afford to be in master channel with this project.

I am running this project in a physical iOS device running iOS 14.2

I just updated to the latest firebase tools by using npm install -g firebase-tools

And the output is:

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
+ firebase-tools@9.0.1
updated 1 package in 22.887s

So I believe the CLI version is 9.0.1

I retried your code sample after updating and it still does not work.

UPDATE:

After poking around and trying out different devices, I realized this works on Android (I tried in the Android emulator) but does NOT work on iOS. I tried both a physical device and the iOS Simulator and it stays without resolving.

markusaksli-nc commented 3 years ago

I'm not seeing this on iOS simulator either. Was not able to connect to the emulator on physical due to some connection issue but it seemed to be working just fine on simulator.

flutter doctor -v ``` [βœ“] Flutter (Channel master, 1.26.0-2.0.pre.84, on macOS 11.0.1 20B29 darwin-x64, locale en-GB) β€’ Flutter version 1.26.0-2.0.pre.84 at /Users/markus/development/flutter_master β€’ Framework revision cda1fae6b6 (4 hours ago), 2020-12-18 04:04:02 -0500 β€’ Engine revision 1be6f414e7 β€’ Dart version 2.12.0 (build 2.12.0-166.0.dev) [βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.1) β€’ Android SDK at /Users/markus/Library/Android/sdk β€’ Platform android-30, build-tools 30.0.1 β€’ Java binary at: /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6953283/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 12.2) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 12.2, Build version 12B45b β€’ CocoaPods version 1.10.0 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio (version 4.1) β€’ Android Studio at /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6953283/Android Studio.app/Contents β€’ Flutter plugin can be installed from: οΏ½ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: οΏ½ https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [βœ“] Connected device (4 available) β€’ Nevercode’s iPhone (mobile) β€’ b668e524315069f3db3661ac11ff1f66afafebdb β€’ ios β€’ iOS 14.2 β€’ iPhone 12 Pro Max (mobile) β€’ CBF5C2A0-A408-4AED-A3DB-B385136B29FA β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator) β€’ macOS (desktop) β€’ macos β€’ darwin-x64 β€’ macOS 11.0.1 20B29 darwin-x64 β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 87.0.4280.67 β€’ No issues found! ```

Is nothing logged to flutter run -v or Xcode console if you wait during the operation?

tapizquent commented 3 years ago

Upon trying again, it does seem to be working now. Maybe an temporary error with Xcode or Firebase that was preventing it from connecting to the local?

Anyways, it works now. Thank you!