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

The client actively closing the connection will trigger an error callback #2264

Open
1 task done
sunjianxu opened this issue Nov 21, 2024 · 1 comment
Open
1 task done

Comments

@sunjianxu
Copy link

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

ws.close(1000, 'Normal closure') 会触发失败。提示信息:WS_ERR_INVALID_CLOSE_CODE 10000

ws version

8.18.0

Node.js Version

19.2.0

System

window10

Expected result

Actual result

Attachments

@lpinca
Copy link
Member

lpinca commented Nov 21, 2024

Please share a minimal reproducible example. I can't reproduce the issue:

import assert from 'node:assert';
import { WebSocket, WebSocketServer } from 'ws';

const wss = new WebSocketServer({ port: 0 }, function () {
  const ws = new WebSocket(`ws://127.0.0.1:${wss.address().port}`);

  ws.on('open', function () {
    ws.close(1000, 'Normal closure');
  });
});

wss.on('connection', function (ws) {
  ws.on('close', function (code, message) {
    assert.strictEqual(code, 1000);
    assert.strictEqual(message.toString(), 'Normal closure');
    wss.close();
  });
});

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

No branches or pull requests

2 participants