More Descriptive Error When WebSocket Closes with Code 1006
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 879
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 68
Description
Bug Description
The new WebSocket library is pretty great, but when a WebSocket connection closes without completing the control frame exchange, it spits out an empty message TypeError, which isn't very descriptive of the problem and appears as an error message that accidentally slipped through the deployment. The exact line of code is:
https://github.com/nodejs/undici/blob/dc5802db4f9940f5f39c3e338f4bd5d64c47e3f4/lib/web/websocket/websocket.js#L589-L591
Reproducible By
Haven't written exact steps to reproduce, but it happens occasionally on connection closure.
Expected Behavior
Perhaps a better description of the connection closure in the ErrorEvent? "Connection closed with code: xyz"
Also imo, would be better to use a plain Error rather than a TypeError.
If this is something the team feels would be a good addition, happy to make a PR
Logs & Screenshots
TypeError\n at #onSocketClose (node:internal/deps/undici/undici:13908:20)\n at TLSSocket.onSocketClose (node:internal/deps/undici/undici:13611:72)\n at TLSSocket.emit (node:events:520:35)\n at node:net:346:12\n at TCP.done (node:_tls_wrap:649:7)
Environment
Ubuntu 20, NodeJS 24.0
Contributor 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.
Research direction
Start in lib/web/websocket/websocket.js at the #onSocketClose code around lines 589-591, and inspect how WebSocket close code 1006 becomes the ErrorEvent. Reproduce the intermittent closure if possible; done means the resulting error is non-empty, describes the connection closure, and uses the agreed error class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100