--reconnection-grace-time does not survive closing the browser tab

未關閉
#7,955 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript
領域
backend, web-dev

研究方向

首先追蹤 BrowserLifecycleService 對 pagehide/beforeunload 的處理,以及 ManagementConnection 的 graceful dispose 清理。接著檢查 RemoteExtensionHostAgentServer 的連線縮短路徑;當設定的 grace period 能在分頁關閉和第二次連線後繼續生效,同時使用預設設定的安裝保留原有行為時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

bug needs-investigation

Problem

--reconnection-grace-time (added in #7678) is documented as "Override the reconnection grace time in seconds. Clients who disconnect for longer than this duration will need to reload the window."

In practice the setting cannot deliver that, for two independent reasons.

1. Closing the tab bypasses the grace time entirely.

BrowserLifecycleService listens on pagehide/beforeunload and runs the workbench shutdown, which disposes the remote connection gracefully. On the server, ManagementConnection treats a graceful dispose as a finished client:

Event.once(this.protocol.onDidDispose)(() => {
    this._log(`The client has disconnected gracefully, so the connection will be disposed.`);
    this._cleanResources();
});

_cleanResources() runs immediately — the grace time is never consulted. So closing the tab kills the session regardless of the configured value.

2. A second connection cuts the grace time to 5 minutes.

RemoteExtensionHostAgentServer shortens every disconnected connection on each new connection:

for (const key in this._managementConnections) {
    this._managementConnections[key].shortenReconnectionGraceTimeIfNecessary();
}

which schedules ProtocolConstants.ReconnectionShortGraceTime (5 min). Opening a second tab is enough to cut a deliberately long grace time back down.

Impact

The use case the flag exists for — leave a long-running task (a build, a CLI, an agent session) running and come back to it later — does not work. The session is gone as soon as the browser is closed.

Expected

When an operator raises --reconnection-grace-time above the default, a disconnected session should survive for the configured duration, including across a closed browser. Installations that never set the flag should keep Code's stock behaviour.

Environment

Reproduced on code-server 4.128.0 and confirmed present in main (4.133.0 / Code 1.133.0).

主要語言
TypeScript
星號
79.4k
分支
6.9k
平均合併
2 天 13 小時
30 天內合併 PR
39

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

coder/code-server 的其他 Issue

查看 coder/code-server 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。