如何修复Firestore“无法到达Cloud Firestore后端”和Firestore无法同步?

时间:2019-09-03 23:03:16

标签: android firebase flutter google-cloud-firestore firebase-authentication

偶尔,我的Flutter应用程序未连接到Firestore并引发以下错误:

6.4.0 - [Firebase/Firestore][I-FST000001] Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: An internal error has occurred, print and inspect the error details for more information.
 This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

此错误不是由于缺少互联网连接,因为其他所有东西都可以正常连接到WiFi。即使有WiFi,即使有更长的等待时间,我的应用也无法连接。

我发现,当我清除模拟器缓存并清除所有数据时,或者当我注销并使用Firebase Auth(使用FirebaseAuth'signInWithEmailAndPassword()'的方法)重新登录到应用程序时,错误消失了。 然后,我所有的应用程序都将与Firestore正确同步。

此外,在出现第一个错误之后,每隔5秒钟左右就会不断出现诸如以下内容的消息,直到我的调试控制台充满了它们:

[C3.1 96DABBD1-6CC6-4E9A-B011-C5EBC32D0E23 127.0.0.1:64613<->216.58.213.234:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.312s, DNS @0.000s took 0.003s, TCP @0.005s took 0.032s, TLS took 0.100s
    bytes in/out: 4846/1139, packets in/out: 7/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C4.1 D7B033A7-E01B-4955-A1D4-F77FD131D1E7 127.0.0.1:64615<->216.58.213.234:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.341s, DNS @0.000s took 0.002s, TCP @0.004s took 0.035s, TLS took 0.136s
    bytes in/out: 5205/1139, packets in/out: 8/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C5.1 6C246F61-0CE5-41B2-96A7-5899459A8CDF 127.0.0.1:64617<->172.217.16.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.341s, DNS @0.000s took 0.003s, TCP @0.004s took 0.031s, TLS took 0.094s
    bytes in/out: 5039/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C6.1 B79FD00C-7B4A-46D4-97D5-A1437FD4065B 127.0.0.1:64619<->172.217.16.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.331s, DNS @0.000s took 0.004s, TCP @0.006s took 0.031s, TLS took 0.101s
    bytes in/out: 5088/1139, packets in/out: 6/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C7.1 FC9A9A87-24F8-4B67-903D-48C20CF85EDC 127.0.0.1:64623<->172.217.16.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.468s, DNS @0.000s took 0.002s, TCP @0.004s took 0.066s, TLS took 0.101s
    bytes in/out: 5246/1139, packets in/out: 6/9, rtt: 0.002s, retransmitted packets: 0, out-of-order packets: 0
    [C8.1 9525CA5F-DD20-4293-89B8-1590FBA8BB3A 127.0.0.1:64627<->172.217.19.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.346s, DNS @0.000s took 0.003s, TCP @0.005s took 0.032s, TLS took 0.105s
    bytes in/out: 5203/1093, packets in/out: 7/8, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C9.1 7373F792-2C38-4583-9CD7-488D270B38FF 127.0.0.1:64631<->172.217.19.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.311s, DNS @0.000s took 0.002s, TCP @0.004s took 0.031s, TLS took 0.103s
    bytes in/out: 4882/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C10.1 A4CA01D7-F8DD-48D6-8F6B-0A7F1B1BE81D 127.0.0.1:64635<->172.217.19.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.318s, DNS @0.003s took 0.007s, TCP @0.014s took 0.033s, TLS took 0.109s
    bytes in/out: 5110/1139, packets in/out: 7/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C11.1 DA879EBE-02BF-4FD4-A63B-708DCD505ED9 127.0.0.1:64637<->172.217.19.74:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 1.032s, DNS @0.000s took 0.002s, TCP @0.004s took 0.031s, TLS took 0.158s
    bytes in/out: 4803/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
    [C12.1 B8C5396A-2168-491E-80C9-3681925B6669 127.0.0.1:64641<->172.217.19.74:443]

一旦发生此错误,尽管从冷启动应用程序,我仍无法与Firestore同步,并且所有写操作仅在本地进行,并且服务器中没有新数据添加到本地。

由于它在注销并重新登录后可以正常工作,因此我包含了相关的身份验证代码。我还没有发现问题,但是可能是因为某些原因导致了错误:

此方法在应用程序的每次启动时运行。

void checkLoginstatusAndNavigate() {
    auth.getUser.then(
      (user) {
        if (user != null) {

          Navigator.pushReplacementNamed(context, '/home');
        } else {
          Navigator.pushReplacementNamed(context, '/start');
        }
      },
    ).catchError((error) {
      print(error);
      Navigator.pushReplacementNamed(context, '/start');
    });
  }

我的应用程序顶部是提供FirebaseUser流的StreamProvider,也许这也很重要。

此外,我没有使用任何VPN,并且我的防病毒软件已关闭。

我将非常感谢您提供的任何见解或帮助,因为这是我在上周一直试图解决的一个错误,没有任何结果:(。

谢谢!

1 个答案:

答案 0 :(得分:0)

在Google Cloud Platform中检查您的API限制,您需要能够访问令牌服务API,否则firebase将无法自动刷新令牌。