Skip to content

Skip empty payload write in Sender.sendFrame - #2341

Closed
SahinurDEV wants to merge 1 commit into
websockets:masterfrom
SahinurDEV:fix/skip-empty-payload-write
Closed

SahinurDEV wants to merge 1 commit into
websockets:masterfrom
SahinurDEV:fix/skip-empty-payload-write

Conversation

@SahinurDEV

Copy link
Copy Markdown

Problem

Sender.sendFrame() writes an unmasked frame as two socket writes (header, then payload) even when the payload is empty. On Electron on some arm64 Linux kernels with a 39-bit address space, net.Socket#write() of a zero-length Buffer fails with EFAULT and destroys the socket. That kills empty server-side ping/pong/message/close() frames (including the automatic pong to an empty client ping) with close code 1006.

Cause

if (list.length === 2) {
  this._socket.write(list[0]);
  this._socket.write(list[1], cb); // zero-length Buffer for empty frames
}

Fix

Skip the payload write when it is empty:

if (list.length === 2 && list[1].length !== 0) {

The frame header already encodes length 0, so the bytes on the wire are unchanged. Masked empty frames are unaffected (they are already a single write).

Tests

Added unit tests that assert an empty unmasked ping is a single write of the header, and a non-empty unmasked ping still uses two writes. Full test/sender.test.js passes; suite otherwise green aside from an unrelated EADDRINUSE flake on port 1337 in this environment.

Fixes #2339

Empty unmasked frames were sent as two socket writes (header +
zero-length payload). On some Electron arm64 kernels a zero-length
write fails with EFAULT and destroys the connection. Skip the payload
write when it is empty; the header already encodes length 0.

Fixes websockets#2339
@lpinca lpinca closed this in 85319a7 Oct 9, 2026
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.

Empty unmasked frames are written as a separate zero-length write, which fails with EFAULT on Electron on some arm64 kernels

1 participant