partyserver: with hibernation off, a client close without a status code (1005) is never answered, so the client stays in CLOSING

未关闭 适合新手
#429 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
69/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
networking

调研方向

首先阅读 closeQuietly 的实现和 #394 中的更改;issue 指明了保留的关闭代码,并提供了使用 hibernate: false 的复现方法。复现不带代码的关闭,并在 6 秒后检查 socket 状态。然后验证修复后客户端会收到 Close 帧并离开 CLOSING。

由索引模型根据 Issue 内容生成。

描述

Since #394, closeQuietly skips the reply for the reserved codes 1005, 1006 and 1015. 1006 and 1015 mean that no Close frame arrived. 1005 does not: it is what the server reports when the client sent a real Close frame with an empty body, which is what ws.close() with no arguments does. The transport is still open, and the client waits in CLOSING for the server's Close frame.

On a non-hibernating server (static options = { hibernate: false }) that frame never comes. y-partyserver's provider calls ws.close() with no code in disconnect(), so every YProvider.disconnect() ends this way. The provider keeps wsconnected === true until the socket finally dies, and a connect() in the meantime does nothing.

The #394 notes say compatibility dates on or after 2026-04-07 auto-reply to Close frames. That does not happen for these sockets: the result below is on compatibility date 2026-11-01.

Repro (wrangler 4.159.0, workerd 1.20261109.1, partyserver 0.5.10, y-partyserver 2.2.0, compatibility date 2026-11-01, hibernate: false):

  1. Start a YServer subclass with hibernate: false (for example via unstable_startWorker).
  2. Open a raw WebSocket to /parties/<party>/<room>, wait for open, then call ws.close() with no code.
  3. With the stock onClose, the client is still in readyState 2 (CLOSING) after 6000 ms.
  4. Add if (code === 1005) connection.close(1000, 'Closed') to onClose. The close completes in 14 ms and the client sees 1000.

In our production Worker that reply has run on every pause, reload and tab close since 2026-11-09. wrangler tail during a test run (57 events) showed no exceptions and no Network connection lost rejections.

Suggested fix: in closeQuietly, skip the reply only for 1006 and 1015. For 1005, reply with ws.close() (no code) or with 1000. A peer that sent a code-less Close frame is still there to receive the answer.

主要语言
TypeScript
星标
1.3k
派生
84
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudflare/partykit 的其他 Issue

查看 cloudflare/partykit 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。