gpt4 book ai didi

javascript - Firebase 数据库失去 websocket 连接,导致延迟

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:50 25 4
gpt4 key购买 nike

我们在 Electron 应用程序中使用 Firebase 实时数据库。身份验证后第一次执行“set”或“update”是完美的。但是,在等待一段时间后(空闲 > 一分钟),执行更新或设置操作会延迟 30 秒,最多延迟 2 分钟。

我们正在执行 promise 中的以下片段:

this.$fbDb.ref().update(updatedNodes).then(() => {
console.log('Successfully created configuration.')
resolve()
}).catch((err) => {
reject(err)
})

firebase 日志显示“Websocket 连接已断开”。请看下面的日志,注意18:21:12.226之前的时间延迟(46秒) :

18:20:26.064 Send.vue?6513:300 Adding the configuration...
18:20:26.065 firebase.js?663c:26 [FIREBASE] 0: update {"path":"/","value":{"/surveys/65/-LDggpvburpfAYAPubqD":{...}}}
18:20:26.091 firebase.js?663c:26 [FIREBASE] event:
18:20:26.092 firebase.js?663c:26 [FIREBASE] event:
18:20:26.092 firebase.js?663c:26 [FIREBASE] event:
18:20:26.093 firebase.js?663c:26 [FIREBASE] event:
18:20:26.094 firebase.js?663c:26 [FIREBASE] event:
18:20:26.094 firebase.js?663c:26 [FIREBASE] event:
18:20:26.095 firebase.js?663c:26 [FIREBASE] event:
18:21:12.226 firebase.js?663c:26 [FIREBASE] c:0:0:0 Websocket connection was disconnected.
18:21:12.226 firebase.js?663c:26 [FIREBASE] c:0:0:0 WebSocket is closing itself
18:21:12.227 firebase.js?663c:26 [FIREBASE] c:0:0: Realtime connection lost.
18:21:12.227 firebase.js?663c:26 [FIREBASE] c:0:0: Closing realtime connection.
18:21:12.228 firebase.js?663c:26 [FIREBASE] c:0:0: Shutting down all connections
18:21:12.228 firebase.js?663c:26 [FIREBASE] p:0: data client disconnected
18:21:12.229 firebase.js?663c:26 [FIREBASE] p:0: Trying to reconnect in 0ms
18:21:12.229 firebase.js?663c:26 [FIREBASE] 0: onDisconnectEvents
18:21:12.230 firebase.js?663c:26 [FIREBASE] p:0: Making a connection attempt
18:21:12.232 firebase.js?663c:26 [FIREBASE] p:0: Auth token refreshed
18:21:12.237 firebase.js?663c:26 [FIREBASE] getToken() completed. Creating connection.
18:21:12.238 firebase.js?663c:26 [FIREBASE] c:0:1: Connection created
18:21:12.242 firebase.js?663c:26 [FIREBASE] c:0:1:0 Websocket connecting to wss://xxx.firebaseio.com/.ws?v=5&ls=abcde&ns=ourproject
18:21:12.843 firebase.js?663c:26 [FIREBASE] c:0:1:0 Websocket connected.
18:21:12.844 firebase.js?663c:26 [FIREBASE] c:0:1: Realtime connection established.
18:21:12.845 firebase.js?663c:26 [FIREBASE] p:0: connection ready
18:21:12.846 firebase.js?663c:26 [FIREBASE] p:0: {"r":13,"a":"auth","b":{"cred":"token"}}
18:21:12.847 firebase.js?663c:26 [FIREBASE] p:0: Listen on /surveys/65 for default
18:21:13.100 firebase.js?663c:26 [FIREBASE] p:0: {"r":14,"a":"q","b":{"p":"/surveys/65","h":"B9G3P0cJefaRilsIFiMp7NHwhYY="}}
18:21:13.102 firebase.js?663c:26 [FIREBASE] p:0: {"r":15,"a":"m","b":{"p":"/","d":{...}}}
18:21:13.115 firebase.js?663c:26 [FIREBASE] p:0: from server: {"r":13,"b":{"s":"ok","d":{"auth":{"provider":"custom","user_id":"ourUser","cid":"65","token":{"exp":1527614289,"user_id":"ourUser","cid":"65","iat":1527610689,"sub":"ourUser","aud":"ourproject","auth_time":1527610689,"iss":"https://securetoken.google.com/ourproject","firebase":{"identities":{},"sign_in_provider":"custom"}},"uid":"ourUser"},"expires":1527614289}}}
18:21:13.252 firebase.js?663c:26 [FIREBASE] c:0:1: Primary connection is healthy.
18:21:13.253 firebase.js?663c:26 [FIREBASE] p:0: from server: {"r":14,"b":{"s":"ok","d":{}}}
18:21:13.253 firebase.js?663c:26 [FIREBASE] p:0: listen response {"s":"ok","d":{}}
18:21:13.309 firebase.js?663c:26 [FIREBASE] p:0: handleServerMessage m {"p":"surveys/65","d":{...}}}
18:21:13.313 firebase.js?663c:26 [FIREBASE] p:0: from server: {"r":15,"b":{"s":"ok","d":""}}
18:21:13.314 firebase.js?663c:26 [FIREBASE] p:0: m response {"s":"ok","d":""}
18:21:13.339 Send.vue?6513:312 Successfully created configuration.

延迟对我们和我们的用户来说是一个非常大的问题。我们无法在 MacOS 或 Linux 上重现它。

这里发生了什么,我们如何解决这个问题或进一步调试它?

最佳答案

经过一些试验和研究(#1#2),我们找到了防止延迟的“解决方法”:

import {INTERNAL as firebaseDbInternal} from '@firebase/database'

// Force firebase database to use long polling instead of websockets
firebaseDbInternal.forceLongPolling()

警告:这似乎不是一个好的解决方案,因为 internal.ts 中的评论 状态:

Customers shouldn't use these (functions) or else should be aware that they could break at any time.

我们很乐意就更好的解决方案提出建议 - 只要没有更好的答案,我就会接受这个答案作为解决问题的最佳方法。

关于javascript - Firebase 数据库失去 websocket 连接,导致延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50589809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com