vscode Apparent lifecycle discrepancy between ManagementPersistentConnection and ExtensionHostPersistentConnection

crcmnpdw  于 2个月前  发布在  Vscode
关注(0)|答案(3)|浏览(31)

当所有扩展都被禁用时,这个问题是否会发生?:是/否

  • VS Code 版本:1.82.2
  • OS 版本:Linux

重现步骤:

  1. 用一个打开的工作区运行 vscode web
  2. 让会话保持运行一段时间,但断开连接
  3. 在超过3小时后重新连接,观察到 "session" 是完整的,但扩展主机消失了
    我们有一个设置,使用 VSCode web 提供代码编辑。系统通常能很好地处理重新连接,但我们在实践中发现了一个角落情况,有时人们会在第二天回来工作时注意到,尽管前一天的会话几乎完整(窗口状态仍然存在,文档可以编辑等),实际上所有的扩展都消失了。
    深入源代码,这似乎是意料之中的,因为扩展主机在与浏览器客户端断开连接3小时后会自愿关闭自己:
    vscode/src/vs/workbench/api/node/extensionHostProcess.ts
    第148行到第151行 dcd8221
    | | constreconnectionGraceTime=ProtocolConstants.ReconnectionGraceTime; |
    | | constreconnectionShortGraceTime=ProtocolConstants.ReconnectionShortGraceTime; |
    | | constdisconnectRunner1=newProcessTimeRunOnceScheduler(()=>onTerminate('renderer disconnected for too long (1)'),reconnectionGraceTime); |
    | | constdisconnectRunner2=newProcessTimeRunOnceScheduler(()=>onTerminate('renderer disconnected for too long (2)'),reconnectionShortGraceTime); |
    我们也可以从我们的日志中看到这一点,其中反映了消息:
2023-11-22 02:15:34.564 [info] Extension host terminating: renderer disconnected for too long (1)
2023-11-22 02:15:34.607 [info] Extension host with pid 4158002 exiting with code 0

当浏览器第二天尝试重新连接时,我们确实看到了我们期望的 PersistentConnectionEventType.ReconnectionPermanentFailure 事件:

2023-11-22 09:14:37.836 [info] Creating a socket (renderer-ExtensionHost-331c07c0-5fba-41a8-bb1c-047f5a04cdf0)...
2023-11-22 09:14:38.213 [info] Creating a socket (renderer-ExtensionHost-331c07c0-5fba-41a8-bb1c-047f5a04cdf0) was successful after 377 ms.
2023-11-22 09:14:38.396 [error] [remote-connection][ExtensionHost][331c0…][reconnect][WebSocket(<URL>:443)] received error control message when negotiating connection. Error:
2023-11-22 09:14:38.397 [error] Error: Connection error: Unknown reconnection token (seen before)
    at H (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:657:25082)
    at o.value (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:657:16703)
    at h.w (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:1902)
    at h.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:2119)
    at s.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:13701)
    at b.z (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:16800)
    at o.value (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:16171)
    at h.w (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:1902)
    at h.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:2119)
    at o.acceptChunk (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:11475)
2023-11-22 09:14:38.397 [error] [remote-connection][ExtensionHost][331c0…][reconnect] A permanent error occurred in the reconnecting loop! Will give up now! Error:
2023-11-22 09:14:38.397 [error] Error: Connection error: Unknown reconnection token (seen before)
    at H (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:657:25082)
    at o.value (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:657:16703)
    at h.w (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:1902)
    at h.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:2119)
    at s.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:13701)
    at b.z (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:16800)
    at o.value (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:16171)
    at h.w (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:1902)
    at h.fire (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:70:2119)
    at o.acceptChunk (https://<URL>/stable-5e932f3b43c571637a183861652b0909ef6da48c/static/out/vs/workbench/workbench.web.main.js:596:11475)

现在这可能没问题,也是应该采用的正确行为(虽然我很想以某种方式自定义它)但是主要问题是,从用户的Angular 来看,他们发现自己处于一种使用半残缺的VSCode示例的情况,其中主要的编辑活动正常进行(因为管理连接没有超时),但扩展主机实际上永远不会重新启动,除非整个窗口被重新加载,因此他们没有任何智能提示功能。
如果意图是在这种情况下使扩展主机能够在关闭后重新启动,那么目前似乎不起作用。
如果意图是让用户重新加载选项卡,那么负责显示此提示的代码目前仅基于主管理连接的状态,而不是扩展主机的状态。

of1yzvn4

of1yzvn41#

感谢您提出这个问题!看起来您可能正在使用旧版本的VS Code,最新稳定版本是1.84.2。请尝试升级到最新版本并检查此问题是否仍然存在。
快乐编码!

g0czyy6m

g0czyy6m2#

我检查了1.82.2...1.84.2,没有看到任何变化告诉我这是在后续版本中修复的。

zf9nrax1

zf9nrax13#

我研究了一下如何解决这个问题,首先我发现从RemoteAgentConnectionStatusListener检索现有的ExtensionHostPersistentConnection示例并不容易,因为它们并没有像IRemoteAgentService那样以1:1的方式存储在RemoteExtensionHost中。不过,我注意到这种情况似乎至少是预料之中的,因为在RemoteExtensionHostAgentServer中有enable-remote-auto-shutdown标志,用于在所有扩展主机消失时关闭整个系统(以及管理连接,我猜)。在这种情况下,你建议这样做吗?

或者,是否应该修改vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts文件中的逻辑?在第475行到第493行之间:

if(isReconnection){
 // 这是一次重新连接
 if(!this._extHostConnections[reconnectionToken]){
  if(!this._allReconnectionTokens.has(reconnectionToken)){
   // 这是一个未知的重新连接令牌
   return this._rejectWebSocketConnection(logPrefix, protocol, `Unknown reconnection token (never seen)`);
  }else{
   // 这是一个过去出现过但现在不再有效的连接
   return this._rejectWebSocketConnection(logPrefix, protocol, `Unknown reconnection token (seen before)`);
  }
 }
}

我想忽略过去的重新连接令牌,而是让它重新创建整个扩展主机?

相关问题