partysocket: a URL provider that rejects with undefined gives an unhandled rejection and stops the reconnection
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- networking
Research direction
The bug is in the .catch() of _connect() in packages/partysocket/src/ws.ts (around lines 585-588), which reads err.message from a rejected URL or protocols provider. Run the repro in the issue against partysocket 1.3.0 to confirm the TypeError and the stalled CONNECTING state. Done means a provider rejecting with undefined or null emits an error event and schedules the next attempt, with no unhandled rejection, and the partysocket test suite passes.
Written by the indexing model from the issue text.
Description
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.
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).
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/partykit
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cloudflare/partykit#444 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cloudflare/partykit#443 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/partykit#430 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
cloudflare/partykit#429 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/partykit#428 ·
All issues in cloudflare/partykit
Similar issues
-
bug parity
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
WenyuChiou/agent-board#1489 ·
Maintainers usually reply within 1 day
-
area: bazaar bug complexity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
accensa/x402-facilitator-stellar#779 ·
Maintainers usually reply within 1 day
-
bug good first issue P4 size:S web-ui
Difficulty 2/5 Half a day Newbie friendliness 85/100
josephfung/curia#2600 ·
Maintainers usually reply within 1 day