Skip to content

websocket: provide descriptive error on abnormal closure (fixes #4625)#4810

Closed
M-YasirGhaffar wants to merge 1 commit intonodejs:mainfrom
M-YasirGhaffar:fix/websocket-1006-error-message
Closed

websocket: provide descriptive error on abnormal closure (fixes #4625)#4810
M-YasirGhaffar wants to merge 1 commit intonodejs:mainfrom
M-YasirGhaffar:fix/websocket-1006-error-message

Conversation

@M-YasirGhaffar
Copy link
Copy Markdown

This relates to...

Fixes #4625

Rationale

When a WebSocket connection closes abnormally (code 1006) without completing the control frame exchange, the error event contained an empty TypeError message. This made debugging difficult as the error appeared cryptic with no description of what went wrong.

Changes

  • Modified lib/web/websocket/websocket.js line 590 to use a fallback message when reason is empty
  • Added test/websocket/issue-4625.js to verify the fix works for abnormal closures

Features

N/A

Bug Fixes

  • When WebSocket closes without receiving a close frame (code 1006), the error message now provides a descriptive fallback: "WebSocket connection closed abnormally" instead of an empty string

Breaking Changes and Deprecations

N/A

Status

Signed-off-by: M-YasirGhaffar <yasirghaffar.nust@gmail.com>
@metcoder95 metcoder95 requested a review from KhafraDev February 6, 2026 11:50
Copy link
Copy Markdown
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard coding a fallback reason here goes against every other piece of code here. #4625 is not a bug either.

@M-YasirGhaffar M-YasirGhaffar deleted the fix/websocket-1006-error-message branch February 9, 2026 18:42
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.

More Descriptive Error When WebSocket Closes with Code 1006

2 participants