我们在Electron应用程序中使用Firebase实时数据库。 执行"设置"或者"更新"认证后第一次完美无缺。但是,等待一段时间后(空闲>一分钟),执行更新或设置操作会延迟30秒,最多延迟2分钟。
我们在承诺中执行以下内容:
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上重现它。
这里发生了什么,我们如何解决这个问题或进一步调试?
答案 0 :(得分:0)
经过一些试验和研究(#1,#2),我们找到了一个"解决方法"这可以防止延迟:
import {INTERNAL as firebaseDbInternal} from '@firebase/database'
// Force firebase database to use long polling instead of websockets
firebaseDbInternal.forceLongPolling()
警告:这似乎不是一个好的解决方案,因为 internal.ts 中的评论声明:
客户不应该使用这些(功能),否则应该知道它们可能随时中断。
我们很乐意就更好的解决方案提出建议 - 只要没有更好的答案,我会接受这个答案作为解决问题的最佳方法。