Fix RTC reconnection and WebSocket connection notification issue#885
Fix RTC reconnection and WebSocket connection notification issue#885CMzhizhe wants to merge 3 commits intolivekit:mainfrom
Conversation
|
davidliu
left a comment
There was a problem hiding this comment.
Can you split these into separate PRs? I'm not sure all of these work as intended, and I'd like to check them independently.
| if (oldVal == ConnectionState.CONNECTED) { | ||
| LKLog.d { "ready call reconnect()" } | ||
| reconnect() | ||
| } else if (oldVal == ConnectionState.RESUMING || oldVal == ConnectionState.RECONNECTING) { |
There was a problem hiding this comment.
This is not needed. If connectionState is resuming or reconnecting, then it's already in the reconnect loop and should not be called again.
There was a problem hiding this comment.
I checked again, and indeed, this part is unnecessary. I will make some modifications
There was a problem hiding this comment.
I have split the PR, and this one is to fix the websocket connection exception
…nnection, no notification was sent to the upper-layer application.
08ecf59 to
27e0214
Compare
我发现了2处bug,都是关于底层重连的问题
1、当我手机断开了网络,LiveKit会产生如下日志,这bug的情况,不是必现的,有概率会出现
websocket 调用onFailure(),liveKit sdk 会帮助我们恢复重连,从 2026-03-14 18:14:57.492 的时间点就可以看见,此时 connectionState 的值是 RESUMING,onIceConnection 的值会是ConnectionState.DISCONNECTED
2026-03-14 18:15:13.065 connectionState 会收到调用 oldVal.connectionState = RESUMING newVal.connectionState = DISCONNECTED ,livekit 漏了处理oldVal.connectionState = RESUMING的情况
When WebSocket calls
onFailure(), the LiveKit SDK helps us recover and reconnect. This can be seen from the time point 2026-03-14 18:14:57.492, whereconnectionStateisRESUMINGandonIceConnectionisConnectionState.DISCONNECTED.At 2026-03-14 18:15:13.065,
connectionStatewill receive calls tooldVal.connectionState = RESUMINGandnewVal.connectionState = DISCONNECTED. LiveKit missed handling the case whereoldVal.connectionState = RESUMING.2、当我手机断开了网络 websocket 无法连接服务器,会调用到 onFailure() ,但是不会通知上层调用者
在onFailure()方法中,只有当wasConnected为true时,才会调用handleWebSocketClose。但在重新连接场景中,WebSocket在尝试重新连接时失败——此时isConnected已经为false(它是由之前的handleWebSocketClose调用或close()方法设置为false的)。因此,由于wasConnected为false,handleWebSocketClose永远不会被调用,这意味着listener?.onClose(...)也永远不会被调用,上层永远不会得到通知。
In the
onFailure()method,handleWebSocketCloseis only called ifwasConnectedis true. However, in a reconnection scenario, the WebSocket fails when attempting to reconnect—at which pointisConnectedis already false (either because of a previous call tohandleWebSocketCloseor because theclose()method sets it to false). Therefore, sincewasConnectedis false,handleWebSocketClosewill never be called, meaninglistener?.onClose(...)will never be called, and the upper layer will never be notified.