首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在中不接收网络断开和重新连接上的文档更新

在中不接收网络断开和重新连接上的文档更新
EN

Stack Overflow用户
提问于 2018-11-15 06:44:59
回答 2查看 768关注 0票数 2

我正在使用Java在本地PC中设置一个用于Firestore查询的手表。如果网络断开并重新连接,则本地计算机将不再接收更新。我观察到,如果网络重新连接发生在一个短时间间隔(< 2-3分钟),那么它是好的。但如果时间更长,这个问题就会发生。此外,在侦听器回调中没有错误/异常通知,以便我可以再次设置更新的监视。我的个人电脑不是一个代理,所以它不能是一个代理问题。

请帮助我调试这个问题。

编辑:

看起来这是SDK中的一个bug。我启用了SDK日志并尝试了以下实验:

  • 设想1:
代码语言:javascript
复制
1. Watch for query updates
2. Client sets up a GRPC connection with the server.
3. Looks like server is sending a keep alive(?) every minute to the client but no keep alive from the client to server
4. Disconnect the network
5. Reconnect within a minute, the query connection is still active and document updates arrive as expected
6. Disconnect the network
7. Reconnect after 5 minutes
8. Here my guess is that the server would have reset the GRPC connection from its end since it cannot reach the client but the SDK doesn't know about this. It is still expecting server to send the keep alive.
9. No document updates are received at the client side (as expected)
10. Issue a new query and watch for its updates.
11. SDK tries to send the query over the same GRPC connection it had established earlier, realizes that the connection is closed, opens a new GRPC connection. Now the document updates start coming for both the queries.

  • 设想2:
代码语言:javascript
复制
1. Watch for query updates
2. Disconnect the network for about 5 minutes
3. Issue a new query before the network is reconnected.
4. SDK tries to send the query over the same GRPC connection it had established earlier, realizes that the connection is closed, opens a new GRPC connection. Even this fails but the connection attempt is retried every minute.
5. Reconnect the network.
6. Connection attempt of SDK succeeds and the updates start coming for both the queries.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-19 05:56:22

必须启用GRPC保持活动,以便客户端向服务器发送持生状态,并检测从服务器端关闭的任何连接。这可以通过在初始化TransportChannelProvider时在FirestoreOptions中提供FirebaseApp来实现。下面给出了代码片段:

代码语言:javascript
复制
InstantiatingGrpcChannelProvider channelProvider =
    InstantiatingGrpcChannelProvider.newBuilder()
        .setKeepAliveTime(Duration.ofSeconds(60L))
        .setKeepAliveTimeout(Duration.ofMinutes(5L))
        .build();

FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder()
    .setChannelProvider(channelProvider).build();

FirebaseOptions options = new FirebaseOptions.Builder()
    .setCredentials(credentials).setFirestoreOptions(firestoreOptions)
    .setConnectTimeout(5000).setReadTimeout(5000).build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(options);

Firestore firestore = FirestoreClient.getFirestore(firebaseApp);
票数 1
EN

Stack Overflow用户

发布于 2018-11-15 09:33:13

当您正在侦听Cloud数据库中的更改并且有一些网络断开时,不幸的是,您无能为力。对于Firebase Firestore SDK如何管理其连接,您没有任何控制。

重试之所以没有像您预期的那么快,是因为执行重试的代码正在取消所谓的指数退避算法。这意味着这段代码可以防止在用户设备上发生的所有重试,从而提高性能。过多的重试也会消耗过多的数据计划,从而影响用户。

作为一个结论,这意味着它可能需要一些时间来恢复联系,你应该对此保持耐心。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53313824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档