Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite crash because of RangeError: Invalid Websocket Frame 1006 WS_ERR_INVALID_CLOSE_CODE #11991

Closed
7 tasks done
samelie opened this issue Feb 8, 2023 · 5 comments · Fixed by #12007
Closed
7 tasks done

Comments

@samelie
Copy link
Contributor

samelie commented Feb 8, 2023

Describe the bug

If the ws dependency module emits an error while HMR is running, it goes unhandled and causes Vite's node process to crash.

node:events:491
throw er; // Unhandled 'error' event

This particular ws throws after the computer goes to sleep and wakes up.

Afaik, this is not reproducible via vite.new

Reproduction

https://stackblitz.com/edit/vitejs-vite-3cq32j?file=index.html&terminal=dev

Steps to reproduce

  1. Start Vite with HMR
  2. Visit your localhost app (Chrome was used)
  3. Put computer to sleep, wait a few seconds
  4. Observe this on your page

image

image

And in terminal:

image

I have a fix for this and will make a PR

In summary,
We need to put an error handler on socket here

You can see the creator of ws approving how the handler was done here

By catching the error on socket, Vite does not crash.

System Info

System:
    OS: macOS 12.6.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 135.20 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.0.0 - ~/.nvm/versions/node/v19.0.0/bin/node
    Yarn: 3.3.1 - ~/.nvm/versions/node/v19.0.0/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v19.0.0/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Firefox: 109.0.1
    Safari: 16.3

Used Package Manager

yarn

Logs

Click to expand! This is the crash
RangeError: Invalid WebSocket frame: invalid status code 1006
at Receiver.controlMessage (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:55108:18)
at Receiver.getData (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:54984:42)
at Receiver.startLoop (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:54700:22)
at Receiver._write (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:54626:10)
 at writeOrBuffer (node:internal/streams/writable:392:12)
 at _write (node:internal/streams/writable:333:10)
 at Writable.write (node:internal/streams/writable:337:10)
at TLSSocket.socketOnData (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:57408:37)
 at TLSSocket.emit (node:events:513:28)
 at addChunk (node:internal/streams/readable:324:12)
 at readableAddChunk (node:internal/streams/readable:297:9)
 at Readable.push (node:internal/streams/readable:234:10)
 at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on WebSocket instance at:
at Receiver.receiverOnError (file:///Users/XXX/node_modules/vite/dist/node/chunks/dep-3007b26d.js:57294:13)
 at Receiver.emit (node:events:513:28)
 at emitErrorNT (node:internal/streams/destroy:151:8)
 at emitErrorCloseNT (node:internal/streams/destroy:116:3)
 at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'WS_ERR_INVALID_CLOSE_CODE',
[Symbol(status-code)]: 1002
}

Node.js v19.0.0


Validations

@github-actions
Copy link

Hello @samelie. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!

@fc
Copy link
Contributor

fc commented Feb 14, 2023

@bluwy he already created the PR

@samelie
Copy link
Contributor Author

samelie commented Feb 14, 2023

#12007

@bluwy
Copy link
Member

bluwy commented Feb 14, 2023

Ah thanks, I didn't catch the link somehow 😅

@samelie
Copy link
Contributor Author

samelie commented Feb 14, 2023 via email

@sapphi-red sapphi-red linked a pull request Feb 17, 2023 that will close this issue
9 tasks
bluwy added a commit that referenced this issue Feb 18, 2023
Co-authored-by: Samuel Elie <selie@anduril.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
futurGH pushed a commit to futurGH/vite that referenced this issue Feb 26, 2023
Co-authored-by: Samuel Elie <selie@anduril.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants