【发布时间】:2020-01-06 19:54:35
【问题描述】:
我的 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,即使等待更长时间也是如此。
我发现,当我使用 FirebaseAuth 'signInWithEmailAndPassword()' 中的方法清除模拟器缓存并擦除所有数据时,或者当我使用 Firebase Auth 注销并重新进入应用程序时,错误就会消失。 然后我的所有应用程序都与 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,并且我的防病毒软件已关闭。
我将非常感谢任何形式的见解或帮助,因为这是我上周一直在尝试修复的错误,但没有任何结果:(。
谢谢!
【问题讨论】:
-
我遇到了类似的错误,我通过删除 app.module.ts 中的
enablePersistence解决了这个问题,也许这对任何人都有帮助。 -
“冷重启”无关紧要,那是一个缓存问题。当您注销时,缓存会失效,因此与清除应用程序的数据相同。
标签: android firebase flutter google-cloud-firestore firebase-authentication