Skip to content

fix(websocket): preserve failed connection error message#5296

Closed
raashish1601 wants to merge 1 commit into
nodejs:mainfrom
raashish1601:codex/4735-websocket-error-message
Closed

fix(websocket): preserve failed connection error message#5296
raashish1601 wants to merge 1 commit into
nodejs:mainfrom
raashish1601:codex/4735-websocket-error-message

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

When a WebSocket connection fails before a parser is available, Undici had the failure reason in failWebsocketConnection() but WebSocket#onSocketClose() initialized the close reason from parser state only. That produced an ErrorEvent with an empty message.

This stores the failed-connection reason on the WebSocket handler and uses it when firing the error event, setting both error.message and the ErrorEvent.message field.

Fixes #4735.

Validation

  • npm run lint -- lib/web/websocket/connection.js lib/web/websocket/websocket.js test/websocket/issue-4735.js
  • npx borp --timeout 180000 -p "test/websocket/issue-4735.js"
  • npx borp --timeout 180000 -p "test/websocket/issue-3546.js"
  • npx borp --timeout 180000 -p "test/websocket/issue-4273.js"
  • git commit pre-hook: npm run lint

@mcollina mcollina requested a review from KhafraDev May 12, 2026 04:52
@KhafraDev KhafraDev closed this May 12, 2026
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.

WebSocket emits error event with an empty message when cannot open connection

2 participants