websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.61k stars 2.42k forks source link

Discrepancy between the documentation and implementation of the WebSocketServer.close method #2172

Closed schrodit closed 11 months ago

schrodit commented 11 months ago

Is there an existing issue for this?

Description

The docs state for WebSocket Server close function that Existing connections are not closed automatically.

But the docs are contrary to the actual behavior of the server: When the WebSocket server is closed, all connected clients are terminated. See the code and a test for exactly that behavior.

So I'm wondering what is the expected behavior?

ws version

7.5.9

Node.js Version

v18.5.0

System

No response

Expected result

According to the docs, the client connection should not be closed when calling WebSocketServer.close().

Actual result

All client connections are terminated on WebSocketServer.close()

Attachments

No response

lpinca commented 11 months ago

The linked documentation is for the master branch. The documentation for the 7.5.9 version (https://github.com/websockets/ws/blob/7.5.9/doc/ws.md#serverclosecallback) correctly states that connections are automatically closed.

schrodit commented 11 months ago

Thanks for pointing me to the correct docs. Didn't noticed that the linked code was also for 7.x.