Skip to content

fix: handle unmatched WebSocket upgrade errors (fix #23727) - #23732

Closed
koriyoshi2041 wants to merge 1 commit into
vitejs:mainfrom
koriyoshi2041:fix-ws-upgrade-reset
Closed

koriyoshi2041 wants to merge 1 commit into
vitejs:mainfrom
koriyoshi2041:fix-ws-upgrade-reset

Conversation

@koriyoshi2041

Copy link
Copy Markdown
Contributor

Problem

A WebSocket upgrade without the vite-hmr or vite-ping subprotocol remains unowned by Vite. If that client resets the connection, the raw socket can emit ECONNRESET without an error listener and terminate the dev server process.

Fix

Attach an error listener before filtering HMR upgrade requests. This keeps unmatched sockets from producing uncaught errors while leaving the socket available to other upgrade listeners.

Test

  • Added a raw WebSocket upgrade regression that verifies unmatched sockets have an error handler.
  • pnpm test-unit packages/vite/src/node/__tests__/http.spec.ts (12 passed)
  • Focused ESLint and git diff --check passed.
  • The regression fails on the pre-fix implementation (expected false to be true).

Risk

Low. The handler is a no-op and does not close or claim unmatched sockets, so proxy/plugin upgrade listeners retain existing behavior. Matching HMR and ping upgrades continue through the existing ws handling path.

@koriyoshi2041

Copy link
Copy Markdown
Contributor Author

Closing as #23728 already covers the same socket-ownership gap with a stronger direct error-emission regression. I missed it during the duplicate check before opening this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant