partysocket: a URL provider that rejects with undefined gives an unhandled rejection and stops the reconnection

オープン 初心者向け
#434 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
networking

調査の方向性

バグは packages/partysocket/src/ws.ts(585〜588行目付近)の _connect() にある .catch() 内にあり、拒否された URL または protocols プロバイダーから err.message を読み取っています。issue の再現手順を partysocket 1.3.0 で実行し、TypeError と CONNECTING 状態での停止を確認してください。完了条件は、undefined または null で拒否するプロバイダーが error イベントを発行し、次の試行をスケジュールすること、unhandled rejection が発生しないこと、そして partysocket のテストスイートが通ることです。

索引モデルが issue の本文から書いたものです。

説明

The .catch() of _connect() reads err.message. When the URL provider (or the protocols provider) rejects with undefined or null, for example with reject() and no argument, that line throws a TypeError inside the .catch(). The result is an unhandled rejection, no error event, and no next attempt: the socket stays in CONNECTING.

https://github.com/cloudflare/partykit/blob/partysocket%401.3.0/packages/partysocket/src/ws.ts#L585-L588

Repro

The packages: [email protected]. Install them with npm i [email protected].

// npm install, then: node repro.ts (Node.js 22.18 or later runs TypeScript directly)
import WebSocket from "partysocket/ws";

process.on("unhandledRejection", (reason) => {
  console.log("unhandledRejection:", String(reason));
});

let calls = 0;
const ws = new WebSocket(
  () => {
    calls++;
    // for example, reject() in a token fetcher
    return Promise.reject(undefined);
  },
  undefined,
  { minReconnectionDelay: 50, maxReconnectionDelay: 50 },
);
let errors = 0;
ws.addEventListener("error", () => errors++);

setTimeout(() => {
  console.log("provider calls in 500 ms:", calls);
  console.log("error events:", errors);
  console.log("readyState:", ws.readyState);
  ws.close();
}, 500);

node repro.ts (Node.js 22.18 or later runs TypeScript directly)

Actual

unhandledRejection: TypeError: Cannot read properties of undefined (reading 'message')
provider calls in 500 ms: 1
error events: 0
readyState: 0

Expected

An error event, and a new attempt after the reconnection delay, as for a provider that rejects with an Error. No unhandled rejection.

A fix

A fix with a new test is on the branch fix/partysocket-provider-rejects-nullish of my fork, at 54a3d36. On a GitHub Actions runner, the new test fails before the change and passes after it, and the whole partysocket suite passes. This repository accepts pull requests only from collaborators, so I did not open a pull request. I can open one if you allow it, or you can take the commit.

I found this with AI assistance (Claude) during a review of WebSocket client libraries. The repro above was run with partysocket 1.3.0 on Node.js 24.22.2 on Linux (a GitHub Actions runner), and the output above is from that run. The fix was also prepared with AI assistance (Claude).

主要言語
TypeScript
スター
1.3k
フォーク
86
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/partykit のほかの issue

cloudflare/partykit の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。