Conversation
…d freezing Two browser behaviors kill open terminal websockets while the server side stays perfectly healthy, and Luna then reports a misleading 'abnormal closure (1006): no Koko end notice' dialog when the user returns: 1. Back-Forward Cache: Chrome/Edge may freeze a page holding websockets on same-tab navigation and drain all of its websockets (the server only sees a clean 1001 going away). Restoring the page from BFCache resurrects a page whose terminal socket is already dead. 2. Background tab freezing: Chromium freezes background tabs under memory / energy pressure, which stops Luna's application-level keepalive pings; intermediate idle timeouts (NLB, reverse proxies) then cut the connection. Fix both at the web image assembly layer: - Serve Cache-Control: no-store for Luna *document navigations* only, by mapping on $http_accept, so such pages are no longer eligible for BFCache. Hashed static assets keep their immutable browser cache. - Install a tiny guard script into Luna's HTML entries (before the app boots) that holds a shared Web Lock per open /koko/ws/terminal websocket. Chromium's background freezing policy exempts pages holding Web Locks, so a terminal tab parked in the background keeps pinging instead of being frozen and cut by idle timeouts. The guard is plain synchronous JS: it wraps the WebSocket constructor, does not touch protocols, terminal data or credentials, and degrades to the original behavior (with a console warning) where Web Locks are unavailable.
3 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题现象
用户在浏览器使用网页终端(Luna)时,以下两个场景回来都会看到弹窗:
而 koko 服务端全程无任何异常,弹窗把锅甩给了网络和 Koko,实际是浏览器行为:
1001 going away)。用户后退返回时页面从 BFCache 原样恢复,终端 WS 早已死亡,Luna 只能按异常关闭报 1006。修复内容
在 web 镜像组装层加两层防护:
luna-bfcache.conf+includes/common.conf:用map $http_accept $luna_cache_control仅对文档导航响应(Accept 含text/html)返回Cache-Control: no-store,使 Luna 页面不再具备进入 BFCache 的资格;带内容哈希的 JS/CSS 等子资源Accept不含text/html,浏览器缓存行为完全不变(add_header对空值不发送头)。utils/luna-terminal-session-guard.js(由install-luna-terminal-guard.sh在构建期注入 Luna 各 HTML 入口,<head>内同步加载于应用启动之前):包装原生WebSocket构造器,仅为/koko/ws/terminal连接在 Web Locks 上持有一把 shared 锁(连接 CONNECTING 阶段即申请、close 即释放,多终端/多标签共享模式互不排队)。Chromium 的后台冻结策略将持有 Web Lock 的页面列为不可冻结,后台标签页因此持续保活,不再被中间层空闲超时回收。脚本特性:文件名带内容哈希(升级不读旧缓存);不改协议、不碰终端数据、不读取凭据;不支持 Web Locks 的浏览器自动退化为原行为并输出 console 警告;暴露
window.__jmsTerminalSessionGuard(supported/activeSockets/heldLocks/failures)便于线上验证。验证
已在基于 v5.0.0-ce 镜像体系的生产环境部署验证:
heldLocks > 0);activeSockets:0、heldLocks:0;Accept: text/html的文档请求响应头为no-store,JS/CSS 子资源响应头不变;utils/附带锁生命周期的 node 单元测试(7 用例通过);nginx 配置通过nginx -t校验。兼容性
/luna/的 HTML 文档响应(新增一个响应头)与 Luna HTML 入口(注入一个静态 JS);/ui/)与其它静态资源的缓存;参考