Skip to content

docs: say what close() and end() do with messages already sent - #1306

Merged
uNetworkingAB merged 1 commit into
uNetworking:masterfrom
dupontbertrand:docs/close-end-send-semantics
Sep 13, 2026
Merged

docs: say what close() and end() do with messages already sent#1306
uNetworkingAB merged 1 commit into
uNetworking:masterfrom
dupontbertrand:docs/close-end-send-semantics

Conversation

@dupontbertrand

Copy link
Copy Markdown
Contributor

Following meteor/meteor#14746 (comment).

close() and end() differ in one way that the current wording leaves implicit: what happens to a message already handed to send(). Measured on 20.66.0, sending one frame and shutting down in the same tick:

call frames the client receives close code
socket.close() 0 1006
socket.end() 1 1005
app.ws('/*', {
  open(socket) {
    socket.send('last message');
    if (process.env.MODE === 'end') socket.end(); else socket.close();
  },
});

Reading "Forcefully" and "Gracefully" as being only about the close frame, we used close() after a final send() and lost that message silently. This adds the syscall mapping you described and names the consequence, so the next reader picks end() without measuring first.

close() maps to the close() syscall, so anything still queued by send()
is not delivered; end() delivers it and then sends the close message.
The distinction was implied by 'forcefully' and 'gracefully' but never
written, and reading close() as the graceful one costs a silent loss of
the last message.
@uNetworkingAB
uNetworkingAB merged commit 6f828b8 into uNetworking:master Sep 13, 2026
1 check failed
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.

2 participants