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

fix websocket receiving an invalid utf-8 in close frame #3206

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web/websocket/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function onSocketClose () {
if (result) {
code = result.code ?? 1005
reason = result.reason
} else if (isClosed(ws) && !ws[kReceivedClose]) {
Copy link
Member Author

Choose a reason for hiding this comment

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

onSocketClose is called once the socket is closed. By the RFC that means we are in the CLOSED state already, we just haven't set it yet.

} else if (!ws[kReceivedClose]) {
// If _The WebSocket
// Connection is Closed_ and no Close control frame was received by the
// endpoint (such as could occur if the underlying transport connection
Expand Down
4 changes: 2 additions & 2 deletions test/websocket/close-invalid-utf-8.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ test('Receiving a close frame with invalid utf-8', async (t) => {
const events = []
const ws = new WebSocket(`ws://localhost:${server.address().port}`)

ws.addEventListener('close', () => {
events.push({ type: 'close', code: 1006 })
ws.addEventListener('close', (e) => {
events.push({ type: 'close', code: e.code })
})

ws.addEventListener('error', () => {
Expand Down
Loading